I’m trying to use an external .net assembly (.dll). It’s an excel spreadsheet writing utility from http://epplus.codeplex.com/. I downloaded the binary .dll from there.
In MonoDevelop, I add the .dll as a referenced assembly. It shows up. I use it in some of my c# scripts, and in MonoDevelop, it builds fine. All references resolved.
I switch back to Unity, and it tells me one of the namespaces from the .dll can’t be resolved and to go fix the compiler error. But it compiles in MonoDevelop. If I add the .dll itself anywhere in my Unity project, Unity tries to scan it and I get this error:
“Unhandled Exception: System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.”
You need to put the DLL in a Plugins folder in your Unity project. No need to compile inside MonoDevelop or add the reference - Unity will do it for you. Note that if the DLL is compiled against .NET 4.0 or greater you’re out of luck unless you can get the source and compile it yourself.
I got the source and built it myself, against .NET 3.5. Dropped it into my Assets\Plugins folder, and I get the same error as I did with the downloaded binary (from http://epplus.codeplex.com/):
"Internal compiler error. See the console log for more information. output was:
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 :0
at Mono.CSharp.RootNamespace.ComputeNamespaces (System.Reflection.Assembly assembly, System.Type extensionType) [0x00000] in :0
at Mono.CSharp.RootNamespace.ComputeNamespace (Mono.CSharp.CompilerContext ctx, System.Type extensionType) [0x00000] in :0
at Mono.CSharp.GlobalRootNamespace.ComputeNamespaces (Mono.CSharp.CompilerContext ctx) [0x00000] in :0
at Mono.CSharp.Driver.LoadReferences () [0x00000] in :0 "
Hm, that’s odd. If it compiled to against 3.5 ok then the other thing to consider is that this plugin might be using an Assembly or Class that isn’t available in the version of Mono that Unity uses. Or the plugin has native code in it and you’re not using Pro, but I glanced at the codeplex project and didn’t see anything right off the bat.
I got an idea, which worked for me in this situation.
I had a file called AssemblyInfo.cs in my project. This is not used by Unity, as far as I know, and it gets in the way of the webplayer compilation. Deleting this file helped for me.