Search Unity

JSON Newtonsoft Error? Help!

Discussion in 'Editor & General Support' started by exzizt, Mar 19, 2018.

  1. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Trying to build my project and get the following error when running the build:


    Mono path[0] = 'C:/Users/User/Documents/BattleToadBuild/BattleToadBuild_Data/Managed'
    Mono config path = 'C:/Users/User/Documents/BattleToadBuild/MonoBleedingEdge/etc'
    PlayerConnection initialized from C:/Users/User/Documents/BattleToadBuild/BattleToadBuild_Data (debug = 0)
    PlayerConnection initialized network socket : 0.0.0.0 55288
    Broadcasting "[IP] 169.254.172.189 [Port] 55288 [Flags] 2 [Guid] 968930217 [EditorId] 4143707104 [Version] 1048832 [Id] WindowsPlayer(EXZIZT-PC) [Debug] 0" to [169.254.255.255:54997]...
    Started listening to [0.0.0.0:55288]
    PlayerConnection already initialized - listening to [0.0.0.0:55288]
    Initialize engine version: 2018.1.0b11 (c5bf62a40d4b)
    GfxDevice: creating device client; threaded=1
    Direct3D:
    Version: Direct3D 11.0 [level 11.1]
    Renderer: NVIDIA GeForce GTX 1080 Ti (ID=0x1b06)
    Vendor:
    VRAM: 11127 MB
    Driver: 23.21.13.9101
    Begin MonoManager ReloadAssembly
    - Completed reload, in 0.058 seconds
    <RI> Initializing input.
    <RI> Input initialized.
    <RI> Initialized touch support.
    UnloadTime: 0.912346 ms
    TypeLoadException: Failure has occurred while loading a type.
    at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System.Type createdType) [0x00005] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00093] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract (System.Type objectType) [0x00007] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x000e1] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00038] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe (System.Object value) [0x00016] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00028] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.JsonSerializer.SerializeInternal (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00253] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.JsonSerializer.Serialize (Newtonsoft.Json.JsonWriter jsonWriter, System.Object value, System.Type objectType) [0x00000] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.JsonConvert.SerializeObjectInternal (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializer jsonSerializer) [0x00028] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value, System.Type type, Newtonsoft.Json.JsonSerializerSettings settings) [0x00007] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at Newtonsoft.Json.JsonConvert.SerializeObject (System.Object value) [0x00000] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    at WorldRunner+<GetStartResponses>c__async0.MoveNext () [0x0004a] in C:\Users\User\Documents\Unity Projects\BattleToad\Assets\Scripts\Models\WorldRunner.cs:69
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <f481764d2f1e4210b1221815368c2272>:0
    at Main+<Execute>c__async1.MoveNext () [0x0011d] in C:\Users\User\Documents\Unity Projects\BattleToad\Assets\Scripts\Main.cs:109
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in <f481764d2f1e4210b1221815368c2272>:0
    at Main+<Awake>c__async0.MoveNext () [0x00109] in C:\Users\User\Documents\Unity Projects\BattleToad\Assets\Scripts\Main.cs:84
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <f481764d2f1e4210b1221815368c2272>:0
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <f481764d2f1e4210b1221815368c2272>:0
    at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00001] in <a4e50d0b3e2849cc8bb09b6e44ab5080>:0
    at UnityEngine.UnitySynchronizationContext.Exec () [0x00021] in <a4e50d0b3e2849cc8bb09b6e44ab5080>:0
    at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00012] in <a4e50d0b3e2849cc8bb09b6e44ab5080>:0
    (Filename: <97722d3abc9f4cf69f9e21e6770081b3> Line: 0)

     
  2. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Is this JSON .NET from the asset store or the official release?
     
  3. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    The official release from Nuget. It miraculously started working. Wish I knew how.
     
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    If it's working, it's working. :) But, if you plan to target multiple platforms, I would use my version from the asset store. It's free.
     
    MNNoxMortem likes this.
  5. EdKirby

    EdKirby

    Joined:
    Nov 15, 2013
    Posts:
    43
    I've been using Dustin's JSON .NET asset for a couple of years now and it's great. He's also great on getting back to you if you have any problems. So, like he said, if you are targeting multiple platforms you'll want to get it.
     
  6. glap

    glap

    Joined:
    Apr 6, 2015
    Posts:
    4
    Hello Dustin,
    I have very similar problem with your asset only when using .Net standart 2.0. The crash throws in windows standalone build. In editor everything works fine.

    Code:
    Code (CSharp):
    1.  
    2.             MemoryStream stream = new MemoryStream(bytes);
    3.             using (BsonReader reader = new BsonReader(stream)) {
    4.                 JsonSerializer serializer = new JsonSerializer();
    5.                 var json = serializer.Deserialize<JObject>(reader);
    6.             }

    Run-time
    Code (CSharp):
    1. TypeLoadException: Failure has occurred while loading a type.
    2.   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator (System.Type createdType) [0x00005] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    3.   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract (Newtonsoft.Json.Serialization.JsonContract contract) [0x00093] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    4.   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateLinqContract (System.Type objectType) [0x00007] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    5.   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract (System.Type objectType) [0x0006d] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    6.   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract (System.Type type) [0x00038] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    7.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.GetContractSafe (System.Type type) [0x00005] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    8.   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType, System.Boolean checkAdditionalContent) [0x0000e] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    9.   at Newtonsoft.Json.JsonSerializer.DeserializeInternal (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00053] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    10.   at Newtonsoft.Json.JsonSerializer.Deserialize (Newtonsoft.Json.JsonReader reader, System.Type objectType) [0x00000] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    11.   at Newtonsoft.Json.JsonSerializer.Deserialize[T] (Newtonsoft.Json.JsonReader reader) [0x00000] in <97722d3abc9f4cf69f9e21e6770081b3>:0
    Could you help me please? :(
     
  7. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    We are using @Dustin-Horne's Json.NET for Unity, and we started getting lots of AOT errors during serialization..

    It turns out that this only happened with the new .NET scripting backend, .NET 4.x. We changed it back to .NET 3.5 and the AOT errors went away.
     
  8. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    @glap @AlienMe send me an email: dustin at parentelement dot com. I'll send you both a .NET 4.6 build which should solve all of those issues.
     
  9. danilo-defilippis

    danilo-defilippis

    Joined:
    Oct 3, 2014
    Posts:
    5
    @Dustin-Horne I'm facing similar issues, could you send me the .NET 4.6 build?
     
  10. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    I think the attached package has all of the platform DLLs but only the IL2CPP DLL is .NET 4.6. When you import, uncheck the other DLLs and only import the IL2CPP one. Then in the inspector, select the /jsondotnet/assemblies/il2cpp/newtonsoft.json.dll and change the mapping to All Platforms and save.

    I'm working on an update and going to see if I can tackle mixed platforms (.NET 3.5 vs .NET 4.6) with asmdefs. I'll update the GitHub repo with the new projects hopefully in the next 3 weeks and push to the asset store as well.
     

    Attached Files:

    chunk_split likes this.
  11. sunmachine

    sunmachine

    Joined:
    Jun 4, 2014
    Posts:
    9
    @Dustin-Horne Any progress - and also, what GitHub repo are you referring to?
     
    chunk_split likes this.
  12. chunk_split

    chunk_split

    Joined:
    Dec 25, 2017
    Posts:
    7
    Hi Dustin, I also upgraded to .NET 4.6 (necessary for unrelated reasons and I can't go back) while also moving to Unity 2018.2.x. I was also having this exact same issue. I tried building via IL2CPP build (including going through the process of installing VS 2017 + tools, rebooting, etc), and while Newtonsoft JSON.NET started working, other things didn't (plus the build times really sucked) so I tried one more thing...

    I moved back to the Mono build, then I simply reinstalled the package again, but removed all of the assemblies except for the AOT one and then it finally worked for me. Hope this helps anyone else having the same issue. :)
     
  13. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    608
    I am getting the same error on Windows standalone build while using the latest asset store version.

    It works fine on iOS, Android and in Editor. It errors out on Windows standalone.
     
  14. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    608
    I think I found the problem. It works when I set api compat. level to .NET 4.x but it doesn't work when I set it to .NET standard 2.0.

    Do you think you can fix that?
     
  15. Xtro

    Xtro

    Joined:
    Apr 17, 2013
    Posts:
    608
    Abandoned?