I’ve encountered what feels like a bug in Silverlight 4, because I can’t find anything in the MSDN docs that says this shouldn’t work, but it’s crashing my application:
var info = Application.GetResourceStream(DocumentUri);
using (var stream = info.Stream)
using (var reader = JsonReaderWriterFactory.CreateJsonReader(stream, XmlDictionaryReaderQuotas.Max))
{
// Content doesn't matter, could be empty.
}
The end result of this block is a NotSupportedException from MS.Internal.InternalMemoryStream.Flush. Stream.Flush is a bit under documented, but it would imply that the enclosing reader should call Stream.CanSeek and/or Stream.CanWrite before calling Flush.
If anyone else has run into this issue, I’d appreciate any references you have.
EDIT: I’ve uploaded a minimal project that’s crashing here: http://sdrv.ms/x9GLNR
I’ve now been able to reproduce your error. I agree with you in that this is a bug in Silverlight. Quite simply, there’s no other reasonable explanation for a NotSupportedException being thrown from deep within classes under the
MSorSystemnamespaces.Nonetheless, I found that your code worked if I changed the Build Action of your
document.jsonfile to Resource instead of Content, and changed the URI used to read the file as follows: