Xamarin.Forms应用在Android上使用Newtonsoft.Json序列化对象时崩溃

Xamarin.Forms应用在Android上使用Newtonsoft.Json序列化对象时崩溃

问题描述:

我正在使用Xamarin将数据发送到专用服务器.我将一些数据序列化,该数据是由ID(int)和DateTime组成的状态对象的数组. 当代码点击此方法时

I am using Xamarin to send data to a private server. I serialize some data which is an array of states objects consisting of an ID (int) and DateTime. When the code hits this method

JsonConvert.SerializeObject(currentStates);

应用程序在模拟器上崩溃,并在输出窗口中显示以下行

The app crashes on the emulator with the following lines in the output window

09-14 10:46:52.677 D/Mono    ( 3313): Config attempting to parse: 
'System.Numerics.dll.config'.
09-14 10:46:52.677 D/Mono    ( 3313): Config attempting to parse: 
'/usr/local/etc/mono/assemblies/System.Numerics/System.Numerics.config'.
09-14 10:46:52.677 D/Mono    ( 3313): Assembly Ref addref 
System.Runtime.Numerics[0x9930e520] -> System.Numerics[0x9930e4c0]: 2
09-14 10:46:52.677 D/Mono    ( 3313): Assembly Ref addref 
System.Numerics[0x9930e4c0] -> mscorlib[0xab19ce40]: 74
Loaded assembly: System.Runtime.Numerics.dll [External]
Loaded assembly: System.Numerics.dll [External]
09-14 10:46:52.715 D/Mono    ( 3313): Assembly Ref addref         
Newtonsoft.Json[0xab19dbc0] -> System.Reflection.Extensions[0xb402d800]: 6
09-14 10:46:52.747 F/        ( 3313): * Assertion at 
/Users/builder/jenkins/workspace/xamarin-android/xamarin-
android/external/mono/mono/metadata/metadata.c:1062, condition `index < 
meta->heap_us.size' not met
09-14 10:46:52.747 F/libc    ( 3313): Fatal signal 6 (SIGABRT), code -6 in 
tid 3313 ()

我拥有Visual Studio Enterprise的最新版本

I have the latest version of visual studio enterprise

Microsoft Visual Studio Enterprise 2017 
Version 15.3.4
VisualStudio.15.Release/15.3.4+26730.15
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

JetBrains ReSharper Ultimate 2017.2    Build 109.0.20170824.131346

Xamarin   4.6.3.4 (0841c2aaf)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.4.3.1 (18558b4)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.12.3.3 (8a39106)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

我也在使用Android SDK 7.1. 我怀疑这行描述了问题

I am also using Android SDK 7.1. I suspected this line describes the problem

09-14 10:46:52.747 F/        ( 3313): * Assertion at 
/Users/builder/jenkins/workspace/xamarin-android/xamarin-
android/external/mono/mono/metadata/metadata.c:1062, condition `index < 
meta->heap_us.size' not met

但是我找不到任何帮助

请帮助,因为我不知道为什么会这样.

Please help as I have no idea why this is happening.

PS以前曾经可以很好地工作,但是在升级nuget程序包之后,它可以工作一段时间,然后又没有任何原因崩溃.

PS it used to work very well before but after upgrading nuget packages it worked well for a while then without any reason it kept crashing.

似乎这是Xamarin中的错误,更新到最新版本后,现在一切正常.

It seems like this was a bug in Xamarin and after updating to the latest version everything is working fine now.