[mono-android] System.IO.Stream.Length - not supported

Jonathan Pryor jonp at xamarin.com
Tue Feb 28 02:17:47 UTC 2012


On Feb 27, 2012, at 7:17 PM, conio wrote:
> I use Stream s = Assets.Open("model.dds");
> Now, I want to read all bytes from this file, so usually in C# I use
> BinaryReader.ReadBytes(Stream.Length). But, here when I in debug mode point with mouse on Length field of this stream I get message that it's not supported.

The reason it's not supported is because the Stream you're using wraps a java.io.InputStream, and the InputStream class doesn't expose any equivalent to the Length property:

	http://androidapi.xamarin.com/?link=T%3aJava.IO.InputStream%2f*

Now, why are you using BinaryReader.ReadBytes(s.Length)? What you can instead do is read + copy the stream into a MemoryStream:

	var dest = new MemoryStream();
	using (var s = Assets.Open ("model.dds"))
		s.CopyTo (dest);
	byte[] data = dest.ToArray ();

 - Jon



More information about the Monodroid mailing list