Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Error with NewtonSoft JSON.NET in .NET Standard 2.0 Plugin in 2018.1

Discussion in '2018.1 Beta' started by NickLandry, Feb 14, 2018.

  1. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    Hi,

    I have a .NET Standard 2.0 DLL I am trying to use as a plugin in 2018.1b7 and I'm getting the following error:

    Unloading broken assembly Assets/Plugins/Newtonsoft.Json.dll, this assembly can cause crashes in the runtime

    My setup:
    1. Project Target: UWP, latest SDK (16299), to be deployed for Windows Mixed Reality.
    2. Scripting Runtime Version: .NET 4.6 Experimental
    3. Scripting Backend: .NET
    4. API Compatibility Level: .NET Standard 2.0
    5. My plugin is a .NET Standard 2.0 DLL configured for all platforms, with Don't process checked since there is no MonoBehaviour in it.
    6. Since my DLL also uses Newtonsoft JSON.NET as a dependency, I imported the .NET Standard 1.3 DLL for Newtonsoft JSON.NET in Unity as a plugin for all platforms, also with Don't process selected.
    Any insights are appreciated on how to enable this scenario in 2018.1. The primary reason why I am using 2018.1 is to leverage the use of .NET Standard 2.0.

    Thanks,
    Nick
     
    soojcho likes this.
  2. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    FYI I get the same error if I use the IL2CPP scripting backend.
     
  3. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
  4. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    Similar in that it's the same error message but the root cause might be different, especially since I have been able to use Newtonsoft JSON.NET successfully in Unity 5.x and 2017.x. The main difference is that I bring in a .NET 4.5 version for Unity Editor + Mono/.NET standalone support, and a WSA version for UWP. Our MRTK actually uses that plugin in the default package. Here the problem stems from using a single .NET Standard version for all platforms since it's supposed to be supported in Unity 2018.1.
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    .NET Standard 2.0 is only supported on Mono and IL2CPP scripting backends. We don't support it on .NET scripting backend.
     
  6. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
    He said that he got the same error on IL2CPP.
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Whoops, I totally missed that. @NickLandry can we get a bug report on this?
     
  8. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    Bug submitted: case 1002502.
     
    Last edited by a moderator: Feb 15, 2018
    LeonhardP likes this.
  9. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Hi there, did you tried with net 4.5 version, it works on my side with other project.
     
  10. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,051
    Event if it works that's a temporary workaround. It needs to be fixed by Unity.
     
  11. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    My custom library is a .NET Standard 2.0 library and it needs to stay like that since it is to be used with a variety of .NET modules, including Xamarin, UWP+XAML, UWP+Unity (for MR), desktop .NET/Mono, and server-side ASP.NET. Yes I have successfully used Newtonsoft JSON.NET as a .NET 4.5 plugin in Unity 5.x and 2017.x, but now I need it to work with .NET Standard 2.0. That's specifically why I am trying 2018.1 beta, otherwise I'd still be in 2017.2.
     
  12. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    It's weird because i'm using a library that is working with Net Standard 2.0, is probably JSON.Net Library then?
     
  13. Kirbyrawr

    Kirbyrawr

    Joined:
    Jul 23, 2012
    Posts:
    945
    Did you try to put a msc file in the Assets folder with this content:

    -langversion:experimental

    Maybe it works for you, who knows.

    I believe that is focusing version 7 of C# instead of 6 and Unity is focusing 6 unless you put this.
     
  14. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    Thanks, good suggestion but no dice. It still complains about Newtonsoft.Json.dll, and I also tried with the latest 2018.1.0b8. This is the #1 Nuget package worldwide, hopefully this gets resolved soon since it's definitely not a fringe scenario.
     
    Kirbyrawr likes this.
  15. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    FYI, it now works in Unity 2018.1.0b9. I made sure to select IL2CPP as my scripting backend. That said, since my .NET Standard 2.0 DLL also has a dependency on Newtonsoft JSON.NET (which was causing the issue), I also switched to the newly released v11 of JSON.NET since it now includes a .NET Standard 2.0 DLL (previous was v1.3). All seems good now. I will report back if I find net standard 2.0 scenarios that break.
     
  16. BitGamey

    BitGamey

    Joined:
    Jun 11, 2016
    Posts:
    52
    I'm getting the same message:

    "Unloading broken assembly Assets/Plugins/Newtonsoft.Json.dll, this assembly can cause crashes in the runtime"

    - Unity 2018.1.0b9
    - VS2017 with all updates (including .NET Standard 2.0 DLL)
    - Copied Newtonsoft.Json.dll to Assets/Plugins
    - Scripting Runtime Version set to Stable (.NET 4.x Equivalent).

    ¯\_(ツ)_/¯
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    What version of .NET Framework is your Newtonsoft.Json.dll targeting?
     
  18. NickLandry

    NickLandry

    Joined:
    Oct 12, 2016
    Posts:
    26
    Which DLL did you pick? First, download the latest v11 of Json.net. When you unzip the Nuget package, use the DLL in the net standard 2.0 DLL. You also need to use IL2CPP. Unity was clear that net standard won't work with the .NET Scripting backend.