- Home /
Cannot load classes from the module: solved
[I include a tl;dr version in the end]
Hello everyone,
I was pulling my hair out because of the problem System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
Unhandled Exception: System.Reflection.ReflectinoTypeLoadException: The classes in the module cannot be loaded.
and some more, related to the two mentioned above I assume.
I am posting this to try and help anyone who encounters such issues when trying to create -> import a .dll file into their project. After many hours of digging into this problem (I learnt a lot more than I needed to, btw) I reached the following conclussion: there was a misunderstanding between the assemblys version of both the .dll trying to be imported and the assembly version Unity beholds (3.5 as of today).
IMPORTANT NOTE: I use mono-develop(built in) as the external tool editor, which will turn out to be quite a powerful tool for those of you who don't use it yet.
My project solution, which was in charge of creating the .dll file I would later try to import into a diferent Unity project, was pointed to be built with a target framework ".NET framework 4.6" while Unity can only withstand ".NET 3.5" at max. Tip: you can check these parameters in the Project tab ->" Options" (where '' is the name of your assembly package. The option just below "Solution Options", in short) -> Build -> General -> Target Framework; for the target framework of the future .dll you'll be assemblying. As for the current version of the framework your Unity instalation can withstand, I'd recommend using the last Unity release so you know it is 3.5 (as of today), but if that is not a possibility you can try printing the System.Environment.Version information via Console.Writeline in a simple script, altough the version printed MAY NOT be the correct one. e.g.: I know I can run up to version 3.5 but when I print this System.Environment.Version it says that the major build number is 2. I may be missing something important here but that's all I managed to get through with the little motivation I had left. You can try and check it manually too by browsing through the different packages imported to your project in the folder "References" in the solution layer of the editor. Double left-click on some of them and the first line of information shown in the recently open tab contains the assembly version it requires [assembly: AssemblyVersion ("3.5.0.0")] Some may be 2.0.0.0, some may be 3.5.0.0 and some may be above this version number if you are trying to import an invalid .dll for Unity (my problem was originated by a library compiled with a target framework 4.6 trying to be succesfully imported into a Unity project). If there is any with an assemblyVersion parameter above 3.5.0.0 you should check if it has been succesfully loaded: open it in the browser half of the tab and check the "References" folder, if there's a red warning, probably implying not being able to load UnityEngine.dll, it means its assembly version is unsupported.
//////////////////###########
TL;DR version
you got problems like System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded. Unhandled Exception: System.Reflection.ReflectinoTypeLoadException: The classes in the module cannot be loaded. and some more.
The assembly version of the .dll you have recently imported into your package is too high for Unity. I assume that such .dll was not downloaded with warranties of working when imported to a Unity project or either was developed by yourself or someone you know. 2nd scenario: Open mono-develop with the solution-library which contains the source code of the .dll. Go to Project tab -> last option -> Build -> General -> Target Framework -> Mono / .NET 3.5 and you're done. Rebuild and import the new .dll 1st scenario: complain to the uploader.
//////////////////##########
Hope this helps~
Your answer
Follow this Question
Related Questions
Keep assemblies in separated dll instead of GameAssembly.dll 0 Answers
How to add a custom module to Unity? 0 Answers
How do I get rid of "Assembly-CSharp-firstpass" and "Assembly-CSharp-firstpass.dll" from my Assets? 1 Answer
IL2CPP mod support 1 Answer
Can't create scripts in unity and visual studio? DLL issues 0 Answers