Silverlight 4 资源流或 Json Xml 字典阅读器中的明显错误
我在 Silverlight 4 中遇到了感觉像是错误的情况,因为我在 MSDN 文档中找不到任何说明这不应该工作的内容,但它使我的应用程序崩溃:
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.
}
此块的最终结果是 NotSupportedException
来自MS.Internal.InternalMemoryStream.Flush
。 Stream.Flush 的记录有点少,但这意味着封闭的读者应该在之前调用 Stream.CanSeek 和/或 Stream.CanWrite调用Flush
。
如果其他人也遇到过这个问题,我将不胜感激您提供的任何参考资料。
编辑:我上传了一个在这里崩溃的最小项目:http://sdrv.ms/x9GLNR
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在已经能够重现您的错误。我同意你的观点,这是 Silverlight 中的一个错误。很简单,对于从
MS
或System
命名空间下的类深处抛出 NotSupportedException 没有其他合理的解释。尽管如此,我发现如果我将
document.json
文件的构建操作更改为资源而不是内容,并更改用于读取文件的 URI,如下所示,您的代码可以正常工作: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
MS
orSystem
namespaces.Nonetheless, I found that your code worked if I changed the Build Action of your
document.json
file to Resource instead of Content, and changed the URI used to read the file as follows: