Silverlight 4 资源流或 Json Xml 字典阅读器中的明显错误

发布于 2025-01-08 20:12:45 字数 708 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

§对你不离不弃 2025-01-15 20:12:45

我现在已经能够重现您的错误。我同意你的观点,这是 Silverlight 中的一个错误。很简单,对于从 MSSystem 命名空间下的类深处抛出 NotSupportedException 没有其他合理的解释。

尽管如此,我发现如果我将 document.json 文件的构建操作更改为资源而不是内容,并更改用于读取文件的 URI,如下所示,您的代码可以正常工作:

var info = Application.GetResourceStream(new Uri("/HelloApp;component/document.json", UriKind.Relative));

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 or System 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:

var info = Application.GetResourceStream(new Uri("/HelloApp;component/document.json", UriKind.Relative));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文