Building DLLs for Unity?

Answered

Has anyone had any luck configuring a Class Library project to build DLLs successfully for Unity? I'm in Unity 5.3.5f1. Any DLL I build results in the following error message after dragging it into the Unity project:

Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.

at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)

at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0

at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in <filename unknown>:0

at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in <filename unknown>:0

at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in <filename unknown>:0

at Mono.CSharp.Driver.LoadReferences () [0x00000] in <filename unknown>:0

at Mono.CSharp.Driver.Compile () [0x00000] in <filename unknown>:0

at Mono.CSharp.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0

Missing method .ctor in assembly C:\<PATH_TO_PROJECT>\Assets\Plugins\TestUnityDll.dll, type System.Runtime.Versioning.TargetFrameworkAttribute
The class System.Runtime.Versioning.TargetFrameworkAttribute could not be loaded, used in TestUnityDll
Can't find custom attr constructor image: C:\<PATH_TO_PROJECT>\Assets\Plugins\TestUnityDll.dll mtoken: 0x0a000001

Googling around suggested my DLL was being built for a too-advanced version of the .NET Framework, so I opened the build settings in Rider and tried other options for "Use MSBuild version". Anything besides "Latest installed" (which is v4.0.30319) results in Rider failing to load the project: "Unable to connect to MSBuild process". These versions do appear to be installed (2.0 and 3.5).

Has anyone managed to build a DLL for Unity successfully?

0
2 comments

Try to switch TargetFrameworkVersion in TestUnityDll.csproj to 3.5.
BTW, have you tried to build your project in VS? (I expect the same result)

The trick to change TargetFrameworkVersion might not work in Linux and MacOS, but on Windows it works for me.

1
Avatar
Permanently deleted user

That seems to have done the trick. Thanks!

(To answer your question I have not tried Visual Studio. I'm not very familiar with the .NET environment as a whole, having come from Java... part of my problem here, no doubt!)

0

Please sign in to leave a comment.