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
Jon Skeet
people
quotationmark

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...

people

See more on this question at Stackoverflow