[BETA] Json.net crashing in release mode

softlionsoftlion Benjamin MayrargueFRBeta ✭✭✭

Hi,
Json.net is working ok on device in debug mode.
In release mode on the same device it was working ok until i switched to beta channel.
Now it crashes with this error:

    at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[Newtonsoft.Json.Linq.JToken].GetResult () [0x00000] in <filename unknown>:0
    InnerException was NullReferenceException: Object reference not set to an instance of an object
       at System.Linq.Expressions.Expression.CreateLambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x00000] in <filename unknown>:0
      at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.Linq.Expressions.ParameterExpression[] parameters) [0x00000] in <filename unknown
    >:0
    I/mvx     (11020):   at Newtonsoft.Json.Utilities.ExpressionReflectionDelegateFactory.CreateParametrizedConstructor (System.Reflection.MethodBase method) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at
    I/mvx     (11020):  Newtonsoft.Json.Serialization.JsonObjectContract.set_ParametrizedConstructor (System.Reflection.ConstructorInfo value) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at
    I/mvx     (11020): Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.Seri alization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0
    I/mvx     (11020):   at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings) [0x00000] in
     <filename unknown>
    I/mvx     (11020):   at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, Formatting formatting, Newtonsoft.Json.JsonSerializerSettings settings

What should i do to make it work ? Go back to stable channel ?

Posts

  • GeirSagbergGeirSagberg Geir Sagberg NOMember

    I have the same problem when I have the linker set to "SDK Assemblies only", and have unchecked "Use shared Mono runtime". Seems to be a problem with the linker, probably due to some kind of reflection. Will tinker some more and see if I can get it working.

  • GeirSagbergGeirSagberg Geir Sagberg NOMember

    I can easily reproduce the problem in a brand new Android project with the following code:

    var obj = new { lat = 63, lng = 10 };
    var jObj = JObject.FromObject(obj);
    

    The last line fails with the following stacktrace:

    [mono] System.NullReferenceException: Object reference not set to an instance of an object
    [mono]   at System.Linq.Expressions.Expression.CreateLambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, System.Collections.ObjectModel.ReadOnlyCollection`1 parameters) [0x00000] in <filename unknown>:0 
    [mono]   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0 
    [mono]   at System.Linq.Expressions.Expression.Lambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.Linq.Expressions.ParameterExpression[] parameters) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Utilities.ExpressionReflectionDelegateFactory.CreateParametrizedConstructor (System.Reflection.MethodBase method) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Serialization.JsonObjectContract.set_ParametrizedConstructor (System.Reflection.ConstructorInfo value) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Linq.JToken.FromObjectInternal (System.Object o, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Linq.JObject.FromObject (System.Object o, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00000] in <filename unknown>:0 
    [mono]   at Newtonsoft.Json.Linq.JObject.FromObject (System.Object o) [0x00000] in <filename unknown>:0 
    [mono]   at LinkerBug.MainActivity+<OnCreate>c__AnonStorey0.<>m__0 (System.Object , System.EventArgs ) [0x0000c] in /Users/geirsagberg/Projects/LinkerBug/LinkerBug/MainActivity.cs:31 
    [mono]   at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) [0x00000] in <filename unknown>:0 
    [mono]   at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) [0x00000] in <filename unknown>:0 
    [mono]   at (wrapper dynamic-method) object:a8e9187e-27a3-48ba-8b2a-523860659bce (intptr,intptr,intptr)
    

    Shared runtime is unchecked, linker is set to SDK Assemblies only. Versions:

    Xamarin Studio
    Version 5.7 (build 661)
    Installation UUID: 7ee9ccab-fedb-4bec-a708-7fbcce481bf3
    Runtime:
    Mono 3.12.0 ((detached/a813491)
    GTK+ 2.24.23 (Raleigh theme)

    Package version: 312000068
    

    Xamarin.Android
    Version: 4.20.0.28 (Business Edition)
    Android SDK: /Users/geirsagberg/Library/Developer/Xamarin/android-sdk-mac_x86
    Supported Android versions:
    2.3 (API level 10)
    4.0.3 (API level 15)
    4.4 (API level 19)
    5.0 (API level 21)
    Java SDK: /usr
    java version "1.7.0_25"
    Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

  • GeirSagbergGeirSagberg Geir Sagberg NOMember

    A workaround: Adding System.Core to "Ignore assemblies" makes it work again.

  • softlionsoftlion Benjamin Mayrargue FRBeta ✭✭✭

    Another workaround: verify that all you references are system references. Some nugets - ie old mvvmcross versions - adds modified system dlls that now exists.

    After doing that, add the binding redirects suggested by visual studio.

    It worked for me.

  • kodejackkodejack Gordon Langford GBUniversity ✭✭

    Thank you Geir Sagberg this also fixed this issue for me. This has only started happening since we upgraded to MvvmCross 3.5.0.

  • softlionsoftlion Benjamin Mayrargue FRBeta ✭✭✭

    Yes this new mvvmcross release don't use the old references anymore, but don't delete them. You should delete them and all will work again nicely.

  • fmatosicfmatosic filip Matošic USMember

    How do I achive:
    Adding System.Core to "Ignore assemblies"
    in xamarin studio?

  • SubhaMuralidharanSubhaMuralidharan Subha Muralidharan USMember ✭✭

    Thanks a lot. Adding System.Core to "Ignore assemblies" worked.

  • rretroorretroo Yurii Yurii UAMember

    Adding of System.Core to "Skip linking assemblies" worked for me too.
    More instruction where to find it in VS.
    Right click on Project.Android -> Properties.
    On this page select tab "Android Options" -> "Linker" and in the field named "Skip linking assemblies" enter "System.Core" (without ".dll").
    If you already have something in this field, separate entries through ";"
    Press Ctrl+S :)

  • RobLanderRobLander Rob Lander GBMember ✭✭

    Btw we are still experiencing this issue with Xamarin.Android 5.1.2.1, Mono 4.0.0, Newtonsoft.Json 6.0.8

Sign In or Register to comment.