简体   繁体   English

Windows Phone 10物理设备和模拟器上的Xamarin Forms反序列化错误

[英]Xamarin Forms de-serialization error on Windows Phone 10 physical device and emulator

I have an app in which I save settings to the local app storage on each device. 我有一个应用程序,其中将设置保存到每个设备上的本地应用程序存储中。 I use the Application.Current.Properties approach to reading and saving data. 我使用Application.Current.Properties方法读取和保存数据。 The challenge I am having is that one of the values I save is an enum that I have defined in my App.xaml.cs file but before the actual 我面临的挑战是,我保存的值之一是我在App.xaml.cs文件中定义的枚举,但在实际
public partial class App : Application declaration. 公共局部类App:应用程序声明。

The challenge I am having is that on any Windows Phone 10 device (physical or emulator), I can only run the application once (when I initially debug it.) If I attempt to launch the application again I am receiving an error that my settings couldn't be loaded because my enum value could not be de-serialized. 我面临的挑战是,在任何Windows Phone 10设备(物理或仿真器)上,我只能运行一次该应用程序(当我初次调试它时。)如果尝试再次启动该应用程序,则会收到我的设置错误由于我的枚举值无法反序列化,因此无法加载。 The exact error message is below. 确切的错误消息如下。

Exception thrown: 'System.Runtime.Serialization.SerializationException' in SYSTEM.RUNTIME.SERIALIZATION.NI.DLL 抛出异常:SYSTEM.RUNTIME.SERIALIZATION.NI.DLL中的'System.Runtime.Serialization.SerializationException'

Additional information: Error in line 1 position 3583. Element ' http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value ' contains data of the ' http://schemas.datacontract.org/2004/07/XXXXX:ge_AppMode ' data contract. 附加信息:错误在第1个位置3583.元素“ http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value ”包含'的数据http://schemas.datacontract.org/2004/07 / XXXXX:ge_AppMode '数据协定。 The deserializer has no knowledge of any type that maps to this contract. 解串器不知道任何映射到该合同的类型。 Add the type corresponding to 'ge_AppMode' 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. 将与“ ge_AppMode”相对应的类型添加到已知类型的列表中-例如,通过使用KnownTypeAttribute属性或将其添加到传递给DataContractSerializer的已知类型的列表中。

Any idea how to fix this so I can test on the Windows Phone 10? 知道如何解决此问题,以便可以在Windows Phone 10上进行测试吗?

So I believe I am going to open this as a defect against Xamarin Forms. 因此,我相信我将打开它作为Xamarin Forms的缺陷。 Basically the only way I could get it to work was to: 基本上,我可以使它工作的唯一方法是:

  1. Uninstall the app 卸载应用
  2. Reboot the phone 重新启动手机
  3. Change the type of the value that was saved in the properties to an integer. 将属性中保存的值的类型更改为整数。

Then every time I access the Int value I cast if back to the enum I need. 然后,每次访问Int值时,如果返回所需的枚举,我都会进行转换。 It is a pain but it seems to work in the WP 8.1 app now. 这很痛苦,但现在似乎可以在WP 8.1应用程序中使用了。 I hope this helps other people and Microsoft if you read this - please fix this issue in Xamarin Forms. 如果您阅读此文章,希望对其他人和Microsoft有帮助-请在Xamarin Forms中解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM