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

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:

  • Project Target: UWP, latest SDK (16299), to be deployed for Windows Mixed Reality.
  • Scripting Runtime Version: .NET 4.6 Experimental
  • Scripting Backend: .NET
  • API Compatibility Level: .NET Standard 2.0
  • 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.
  • 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

1 Like

FYI I get the same error if I use the IL2CPP scripting backend.

Similar?

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.

.NET Standard 2.0 is only supported on Mono and IL2CPP scripting backends. We don’t support it on .NET scripting backend.

He said that he got the same error on IL2CPP.

Whoops, I totally missed that. @NickLandry can we get a bug report on this?

Bug submitted: case 1002502.

1 Like

Hi there, did you tried with net 4.5 version, it works on my side with other project.

Event if it works that’s a temporary workaround. It needs to be fixed by Unity.

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.

It’s weird because i’m using a library that is working with Net Standard 2.0, is probably JSON.Net Library then?

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.

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.

1 Like

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.

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).

¯_(ツ)_/¯

What version of .NET Framework is your Newtonsoft.Json.dll targeting?

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.