.NET 4.6 Dll's references problem

Hi guys!

I’m actually trying Unity 2017 and am thrilled to have .net 4.6 inside of it!

I’m trying to update my custom build SignalR dll for .net 30 who worked perfectly for years now. So the idea is to put SignalR 2.2.2 inside Unity. Everything works just fine : I managed to change the target framework to 4.6 Experimental, Import the Signalr and Newtonsoft.Json Dll’s inside the project, use the lib inside the code, … It’s just… amazing!

Everything works perfectly but only in player mode… If I try to build a “.exe” I get a strange error

ArgumentException: The Assembly System.Runtime is referenced by Newtonsoft.Json (‘Assets/Newtonsoft.Json.dll’). But the dll is not allowed to be included or could not be found.

At first I thought … yeah okey there is the “System.Runtime” DLL missing in the project… weird because newton.json doesn’t say that they need this dependency but okey… I added it… this error gone away and another of the same type came asking for another DLL…

I tried for a couple of hours to add all the desired DLL’s but after the 10th I gave up because it seemed to me that it needed something else…

Do you guys have any clues? … I most definitely think that it’s a bug… especially when it works like charm in the player mode…

The System.Runtime.dll assembly is part of the .NET Standard profile, which is not supported by Unity in 2017.1. I would guess that Newtonsoft.Json.dll in your project is built against .NET Standard (maybe it came from nuget?). See if you can find a Newtonsoft.Json.dll assembly that is built against the .NET Framework.

Note that we are working to correct this situation. A future version of Unity (it looks like 2017.3), will support both the .NET Framework profile and the .NET Standard 2.0 profile.

Thanks Josh!

I’m actually using Unity 2017.3 :slight_smile: but I think that’s gonna come in the further updates :wink:
I’m so thrilled that you put the new .net standard in unity it offer so much possibilities! <3 Unity!!

So I’m gonna try to downgrade my dll’s to .net 45.

Thanks again!!!

Yes, this change has not yet landed in 2017.3.

Thanks for the info!

So I tried to downgrade my dll’s to :

Which don’t refer to .net Standard and are compatible with .net 45 and I still get the exact same problem.

When I downgrade all the way to SignalR 1.0.1 it works better but crashes the executable with :

UnityPlayer.dll caused an Access Violation (0xc0000005) in module UnityPlayer.dll at 0033:3a8c78e7.

O_o Any clue?

I’m not sure. If some assembly is referencing System.Runtime.dll, then something in there is not using the .NET Framework. We have found issues like the are rather difficult to sort out. Maybe you can open the assemblies in ILSpy to see their references.

I’m unsure about the crash. Does the same thing work in the editor?

SignalR 2.2.2, 2.1.1 and 1.0.1 are working perfectly in the editor! I’m not familiar of ILSpy but i’m gonna try to google it!

EDIT :
It seems on ILSpy that
microsoft.aspnet.signalr.client.2.2.2 reference → System.Reflection which is fine… I guess?
newtonsoft.json.6.0.4 reference → System.Runtime.Serialization.Formatters who causes the problem O_o?

It might be worth submitting a bug report then. If this works in the editor but crashes in the player, that sounds wrong.

Sorry, maybe we misunderstood. There’s no error in the editor, no error in the play mode. It just won’t build a .exe “CTRL+B”

It seems on ILSpy that
microsoft.aspnet.signalr.client.2.2.2 reference → System.Reflection which is fine… I guess?
newtonsoft.json.6.0.4 reference → System.Runtime.Serialization.Formatters who causes the problem :eyes:?

Yes, I misunderstood. Can you provide the full error message when the build fails?

If these are System.Reflection.dll and System.Runtime.Serialization.Formatters.dll (the assemblies, not the namespaces), then you are still referencing things in .NET Standard, which makes sense based on the error you see.

Here’s the 3 errors coming when building :

ArgumentException: The Assembly System.Runtime is referenced by Newtonsoft.Json (‘Assets/Newtonsoft.Json.dll’). But the dll is not allowed to be included or could not be found.
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1[T] alreadyFoundAssemblies, System.String[ ] allAssemblyPaths, System.String[ ] foldersToSearch, System.Collections.Generic.Dictionary2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:145)
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1[T] alreadyFoundAssemblies, System.String[ ] allAssemblyPaths, System.String[ ] foldersToSearch, System.Collections.Generic.Dictionary2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:151)
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List1[T] alreadyFoundAssemblies, System.String[ ] allAssemblyPaths, System.String[ ] foldersToSearch, System.Collections.Generic.Dictionary2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:151)
UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[ ] paths, System.String[ ] foldersToSearch, UnityEditor.BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:185)
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

Build completed with a result of ‘Failed’
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x0020e] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:181
at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00065] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:88
UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

The ILSpy SignalR 2.2.2 and Newtonsoft.Json 6.0.4 output


Ok, it looks like the issue is still with assemblies built against .NET Standard, based on your build log.

In ILSpy that looks OK, I don’t see anything not in .NET Framework. Can you expand the Newtonsoft.Json part of the tree though?

I uploaded it in my previous post (2nd screenshot)

This Newtonsoft.Json assembly is built against .NET Standard, not .NET Framework. Those are all assemblies from .NET Standard still.

Fudge…

So my two alternatives are :
Downgrade to SignalR 1.0.1 and struggle with the memory violation problem
Wait till Unity 2017.3 has .NET Standard support

Is that right? Can you tell me an ETA of .net standard in Unity?

Yes, that sounds correct. I don’t have an ETA yet. We’re close to landing .NET Standard support in 2017.3. But until it is ready I don’t want to commit.

2 Likes

Josh, thanks a lot!

I think i’m gonna wait :slight_smile:

Hi,

I’m triyng to use a dll (SpeechClient) from the nuget package (Microsoft.ProjectOxford.SpeechRecognition-x64) in to Unity. I put the DLL in Assets/Plugins folder but is no referenced in the code.

Any idea if i can do this and how?

Regards.-

I’m not sure what you mean by this, can you elaborate about the problem? If this assembly built against .NET Standard 2.0, it should work with the Unity 2018.1 beta releases. However, the assembly might depend on something platform specific, so it might be restricted to only work on certain platforms.