- Home /
Unity 2017.1 .NET 4.6 Plugin - System.Runtime assembly not allowed to be included?
I am using a plugin compiled for .NET 4.6, which depends on System.ValueTuple. I'm using version 4.3.0 of this package. Everything works ok in the editor, but when I attempt to build for Windows or Mac OS X I get the following error. Could anybody shed some light on what the issue is here?
ArgumentException: The Assembly System.Runtime is referenced by System.ValueTuple ('Assets/Plugins/System.ValueTuple.dll'). But the dll is not allowed to be included or could not be found.
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1[T] alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:142)
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1[T] alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:148)
UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1[T] alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2[TKey,TValue] cache, UnityEditor.BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:148)
UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, UnityEditor.BuildTarget target) (at /Users/builduser/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:179)
UnityEditor.HostView:OnGUI()
Additional details: I'm experimenting with running a tensorflow neural network from within Unity. I'm using the rather nice TensorFlowSharp wrapper to do it. However, the wrapper targets 4.6.1 so I have retargeted for 4.6 (fork available here). If I can't get this to work, I'll have to write my own native calls which will be a pain.
Answer by davidaver · Oct 25, 2017 at 12:44 AM
Recently had a the same problem with a .NET 4.6 library that references System.ValueTuple. Copying the following .dlls from Unity's Mono folder (C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\4.5\Facades) into your project's assets folder should do the trick.
System.Collections
System.Resources.ResourceManager
System.Runtime
Answer by drhawley · Jan 13, 2018 at 07:46 PM
Trying @davidaver 's suggestion did not cause the error to stop occurring for me. Also tried changing "4.5" to "4.6.2-api", to no effect. --- On Linux, Ubuntu 16.04
Answer by ZackSheppard · Nov 12, 2018 at 11:56 PM
I am bumping into this same issue. Putting the assemblies into my project has not done any good (though it allows me to build vs getting the exceptions). When I put the assemblies in it seems to build but is not working properly.
I built a library outside of unity in .NET Standard 4.6 and am trying to import it into unity (using Unity Editor 2017.3.0f3). I am able to play my game in editor perfectly fine, but when I try and build it is telling me that System.Runtime.dll could not be loaded in and fails my build
I would love some help getting this resolved :(. I feel like I should be able to make third party libraries and have them imported.
I would like to note that my library depends on a NuGet package that also has dependencies on System.Threading.Tasks.Extensions.dll and System.ValueTuple.dll. Since this was built outside of unity it is NOT using the mono specific versions in the %editor_install_path%\Unity\Editor\Data\MonoBleedingEdge\lib\mono\ directories. I suspect there is some confusion when unity is trying to resolve to it's own special flavors of these assemblies.
I will make sure and post if I find anything in particular. Going to try and see if this happens in the latest editor version in the meantime
I discovered some very strange things and ended up solving my problem. The summarized version of it is that my non-unity project was referencing a NuGet package that was dependent on System.Runtime.dll specifically for .net version 4.5 and I was trying to give it System.Runtime.dll from version 4.6 since I was building for that version. After I placed the unity (mono) versions of System.runtime.dll (and others) into a Plugins folder in my unity project, I was able to make and use builds.
Quick recap: 1) I am attempting to build a non-unity library in .NET 4.6 outside of my unity project and bring in the dlls for use inside unity 2017.3.0f3. 2) I was seeing an error about dlls that could not be used when building my project and this would fail my builds entirely 3) I had attempted to add the dlls unity complained about into my project (in plugins folder) with no luck. I was specifically trying to bring in the unity versions of assemblies from the %editor_install_path%\Unity\Editor\Data\$$anonymous$$onoBleedingEdge\lib\mono\ directory
I ended up looking through the dependencies of my library and targeted an inner dependency of the $$anonymous$$essagePack NuGet package. $$anonymous$$essagePack was dependent on System.Threading.Tasks.Extensions (NuGet package) and System.ValueTuple (NuGet package). Reviewing the NuGet page for System.Threading.Tasks.Extensions revealed that the dependency was for .NET version 4.5. I simply changed my .NET version for the project(s) to 4.5 and re-built and then added those assemblies to the project. I then grabbed the .NET version of System.Runtime.dll (and others that I discovered in my build logs) from %editor_install_path%\Unity\Editor\Data\$$anonymous$$onoBleedingEdge\lib\mono\4.5 and dropped em' into the plugins directory. Suddenly I COULD BUILD!!!
I think I had assumed that the dependency on System.Runtime.dll was due to my library root (which was previously .NET 4.6... so I assumed i needed to mono .NET 4.6 equivalent assemblies in unity) ins$$anonymous$$d of the lower version co$$anonymous$$g from the dependency chain in NuGet (which wanted the .NET 4.5 assemblies ins$$anonymous$$d). Glad I got this sorted.
I should also mention that I had this really silly bug in the editor where I would immediately get BadImageFormatExceptions (that were non-clearable and prevented compilation) when I would bring in the mono assemblies. I followed the stack and realized it was co$$anonymous$$g from the unityscript compiler. Just as a random test (because let's face it... who uses unityscript anymore?) I deleted all .js and .boo files from my project and that made the error go away. I was very surprised by this and am posting it in case it might help out.
Your answer
![](https://koobas.hobune.stream/wayback/20220612134702im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Where does Unity5 look for native plugin dependencies in the editor on Windows? 1 Answer
Native Android plugin CPU subfolder approach not working 1 Answer
Game with Math.NET Numerics works fine on Windows, but not on OSX 1 Answer
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers