【问题标题】:UWP exception in release mode only仅发布模式下的 UWP 异常
【发布时间】:2020-10-11 20:51:06
【问题描述】:

我正在尝试将 XmlReader 加载到 System.ServiceModel.Syndication.SyndicationFeed 并且它仅在发布模式下导致异常,但在调试模式下工作

加载代码

using (var xmlReader = XmlReader.Create(new StringReader(stringXML), new XmlReaderSettings { Async = true, IgnoreWhitespace = true, IgnoreComments = true }))
{
    System.ServiceModel.Syndication.SyndicationFeed feed = System.ServiceModel.Syndication.SyndicationFeed.Load(xmlReader);
}

例外

System.Reflection.MissingRuntimeArtifactException: ‘Cannot retrieve a MethodInfo for this delegate because the method it targeted (System.ServiceModel.Syndication.SyndicationFeedFormatter.DefaultUriParser(XmlUriData, Uri&)) was not enabled for metadata using the Dynamic attribute. For more information, please visit https://go.microsoft.com/fwlink/?LinkID=616868’

和xml内容https://mspoweruser.com/feed

【问题讨论】:

  • 当您构建发布版本时,您正在测试应用程序的 .NET Native 构建。非常不同的是,它是一个提前编译器,存储服务器在将二进制文件交付给应用程序用户之前使用的编译器。反射是在这种情况下往往无法正常工作的一个功能,谷歌“.net native compile errors”以了解如何使用 rd.xml
  • 您是否点击了错误消息中的链接?它会将您带到为您编写 rd.xml 的向导。
  • 我做到了,我认为这只是关于 UWP 中的东西,但是在另一个基于 .net 标准的项目中代码粉碎,直到 Hans Passant 指出我应该搜索 .net 本机编译错误,我当时就知道了它会影响一切

标签: c# uwp .net-standard


【解决方案1】:

将此代码添加到 Default.rd.xml 文件可解决问题

<Library Name="SyndicationFeed">
  <Assembly Name="System.ServiceModel.Syndication" Activate="Required All" Browse="Required All" Serialize="Required All" Dynamic="Required All" />
  <Namespace Name="System.ServiceModel.Syndication" Dynamic="Required All" />
</Library>

&lt;/Application&gt; 之后和&lt;/Directives&gt; 之前

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2010-10-31
    • 1970-01-01
    • 2016-02-02
    相关资源
    最近更新 更多