C# Application.Current.Properties反序列化崩溃

C# Application.Current.Properties反序列化崩溃,c#,.net,serialization,xamarin.forms,C#,.net,Serialization,Xamarin.forms,我将对象存储到属性(如果尚未存储): 它存储了第一个对象。然后我将其设置为空。当我再次尝试检查ContainsKey时,它会引发一个异常: System.AggregateException: 'One or more errors occurred.' SerializationException: Error in line 1 position 264. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:V

我将对象存储到属性(如果尚未存储):

它存储了第一个对象。然后我将其设置为空。当我再次尝试检查
ContainsKey
时,它会引发一个异常:

System.AggregateException: 'One or more errors occurred.'
SerializationException: Error in line 1 position 264. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data of the 'http://schemas.datacontract.org/2004/07/Layouts.Models:User' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'User' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.

我应该删除。。。什么?

使用应用程序.Current.Properties.Remove(键)使用应用程序.Current.Properties.Remove(键)检查以下文档:

注意:属性字典只能序列化的基元类型 存储尝试存储其他类型(如列表)可以 默默地失败

在主题“持久性”中写着:“属性字典会自动保存到设备中。”因此,您会立即收到异常

解决方法是手动序列化/反序列化用户对象。下面是一个使用JSON序列化的示例:

检查位于以下位置的文档:

注意:属性字典只能序列化的基元类型 存储。尝试存储其他类型(如列表) 默默地失败

在主题“持久性”中写着:“属性字典会自动保存到设备中。”因此,您会立即收到异常


解决方法是手动序列化/反序列化用户对象。下面是一个使用JSON序列化的示例:

我不能。一旦我调用
Application.Current.Properties
,它就会引发该异常。我不能。一旦我调用
Application.Current.Properties
,它就会引发该异常。
System.AggregateException: 'One or more errors occurred.'
SerializationException: Error in line 1 position 264. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data of the 'http://schemas.datacontract.org/2004/07/Layouts.Models:User' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'User' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.