问题描述
我正在尝试将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 @R_576_4045@ion,please visit https://go.microsoft.com/fwlink/?LinkID=616868’
和xml内容https://mspoweruser.com/feed
解决方法
将此代码添加到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>
在</Application>
之后和</Directives>
之前