我使用棱鏡6 UWP和Microsoft.NetCore.Uwp 5.2.2。我在Release版本中遇到了問題,我無法使用反射。UWP .NET原住民問題
我有這樣的對象作爲IDictionary<string, ReadOnlyCollection<string>>
。如何在default.rd.xml中爲他們添加策略?
我使用棱鏡6 UWP和Microsoft.NetCore.Uwp 5.2.2。我在Release版本中遇到了問題,我無法使用反射。UWP .NET原住民問題
我有這樣的對象作爲IDictionary<string, ReadOnlyCollection<string>>
。如何在default.rd.xml中爲他們添加策略?
在我的項目,我們最近也有類似的問題與IDictionary
,看到here。我不知道是否該錯誤信息是與你相似,但在我們的情況下,解決方案是在類似這樣的.rd.xml文件添加運行指令:
<Type Name="System.Collections.Generic.IDictionary{System.String,System.Collections.ObjectModel.ReadOnlyCollection{System.String}}" MarshalStructure="Excluded" />
我無法重現您的問題。我在包含IDictionary<string, ReadOnlyCollection<string>>
對象的發佈模式下運行項目,並且我沒有遇到任何錯誤或異常。我的操作系統版本是建立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
配置文件的詳細信息,請參考this article。如果在某些反射場景中獲得MissingMetadataException
,則可以按照this blog來解決您的問題。
謝謝。我會嘗試。問題是,當應用程序掛起和終止時,我使用此屬性來保存它。我不知道你是否熟悉Prism庫,但是我使用'[ReatorableState]'屬性來覆蓋所有我想要保存的屬性。棱鏡會話狀態服務使用此屬性。我得到'InvalidDataContractAttribute異常' –
謝謝,這是幫助。這個問題並不完全在MarshalStructure策略中,我只需要知道語法 –