![](/img/trans.png)
[英]Problems with DataContractSerializer + DataContractResolver on UWP, .NET Native issue?
[英]UWP .NET Native Issue
我正在將Prism 6用於UWP和Microsoft.NetCore.Uwp 5.2.2。 我在發行版中遇到了無法使用反射的問題。
我有IDictionary<string, ReadOnlyCollection<string>>
這樣的對象。 如何為他們在default.rd.xml中添加策略?
我無法重現您的問題。 我在發布模式下運行一個項目,該項目包含IDictionary<string, ReadOnlyCollection<string>>
對象,並且我沒有遇到任何錯誤或異常。 我的OS版本是內部版本14393,我在本地計算機上對其進行了測試。
由於我不確定您遇到了什么錯誤或異常,因此可以嘗試將以下集合相對策略添加到default.rd.xml
。
<Assembly Name="*Application*" Dynamic="Required All" />
<!--Add your application specific runtime directives here.-->
<Namespace Name="System.Collections.ObjectModel" >
<TypeInstantiation Name="ReadOnlyCollection"
Arguments="ContosoClient.DataModel.ProductGroup" Serialize="Public"/>
<TypeInstantiation Name="ObservableCollection"
Arguments="ContosoClient.DataModel.ProductItem" Serialize="Public" />
<TypeInstantiation Name="ReadOnlyObservableCollection"
Arguments="ContosoClient.DataModel.ProductGroup" Serialize="Public" />
</Namespace>
有關rd.xml
配置文件的更多詳細信息,請參考本文 。 如果您在某些反射情況下遇到MissingMetadataException
,則可以關注此博客以解決問題。
在我的項目中,我們最近在IDictionary
遇到了類似的問題,請參見此處 。 我不知道該錯誤消息是否與您的錯誤消息相似,但是在我們的案例中,解決方案是在.rd.xml文件中添加類似於以下內容的運行時指令:
<Type Name="System.Collections.Generic.IDictionary{System.String,System.Collections.ObjectModel.ReadOnlyCollection{System.String}}" MarshalStructure="Excluded" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.