Exception Building APK: The classes in the module cannot be loaded - Mono2x Scripting Backend

Edit: This was reproduced with a new blank project by adding a single, random dll to the Asset folder, and then a single cs script that has a reference to that dll. Then, switching the scripting backend to Mono2x, and building, reproduces the issue. Unity 5.3.4 p5.

I’ve created a bug with Unity.

Hello,

I am encountering a very odd error that I have been debugging for several days now. I have found some others online who encountered a similar or identical issue, and their ways to circumvent this exception have not worked, or cannot be used in my situation.

This issue happens when I build my Android project to an APK.

Here are the things that may potentially fix the issue that I CANNOT do:

  • Switch to IL2CPP as my scripting backend. It must stay as Mono2x for the Android project.
  • Switch from .Net 2.0 (subset) to .Net 2.0

I have confirmed that while the exception (posted below) mentions a specific dll, that the issue is not a problem with the dll’s themselves. If I download the source code for the erred dll, and replace the dll with the source code, then the next error will show the next dll in the list as the one that could not be loaded.

This issue only started to occur for anyone when we upgraded Unity 5.3.3 p2 to 5.3.4 p5.

Thank you for any advice!

Here is the exception:

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

The following assembly referenced from /Users/jenkins/Perforce/Automation/Android/client/Assets/Plugins/P31RestKit.dll could not be loaded:
    Assembly:   UnityEngine    (assemblyref_index=0)
    Version:    0.0.0.0
    Public Key: (none)
The assembly was not found in the Global Assembly Cache, a path listed in the MONO_PATH environment variable, or in the location of the executing assembly (/Users/jenkins/Perforce/Automation/client/Assets/Plugins/).

Have you tried temporarily removing P31RestKit.dll and all of its references?

Hi Ryan,

The issue is not in the DLL’s shown in the error. We can replace any of the DLL’s with their source code versions, and the error hops over to the next dll that is processed during the build.

This was reproduced with a new blank project by adding a single, random dll to the Asset folder, and then a single cs script that has a reference to that dll. Then, switching the scripting backend to Mono2x, and building, reproduces the issue. Unity 5.3.4 p5.

I’ve created a bug with Unity.

1 Like