Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a StreamReader to a Stream

The Deserialize method in protobuff-net takes in a Stream as a argument. Before I used to use FileStream and pass that and it worked , but now I have to use StreamReader cause I'm porting the app for windows store/phone. and I'm getting the following error :

 error CS1503: Argument 1: cannot convert from 'System.IO.StreamReader' to 'System.IO.Stream'

Also this is a unity3d project and the other error I'm getting is :

error CS4028: 'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Storage.StorageFolder>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?

This is weird because I have wrapped the code in #if NETFX_CORE #endif Here are the includes I'm using:

#if NETFX_CORE

using System.IO;
using System.Threading.Tasks;
using Windows.Storage;
#endif
like image 748
Uri Popov Avatar asked Jun 07 '26 20:06

Uri Popov


1 Answers

You can't, logically - a StreamReader is for text data, whereas protobuf data is binary data. It's not clear where you're getting the StreamReader from, but you should look for APIs designed for binary data instead.

In practice, you may be able to use StreamReader.BaseStream to get at the underlying stream, but you shouldn't be creating a StreamReader to read from non-text data anyway... and constructing the reader may try to read text data from the stream and complain if it doesn't find it...

like image 130
Jon Skeet Avatar answered Jun 09 '26 11:06

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!