Search Unity

External .net assembly not loading

Discussion in 'Scripting' started by akevan, Apr 25, 2013.

  1. akevan

    akevan

    Joined:
    Apr 6, 2013
    Posts:
    10
    I'm on Unity 4 on a Mac.

    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."

    Any ideas what's wrong?
     
  2. MicroEyes

    MicroEyes

    Joined:
    Jul 3, 2012
    Posts:
    309
    If you are planning to port for WebPlayer then you should better read this.
     
  3. akevan

    akevan

    Joined:
    Apr 6, 2013
    Posts:
    10
    I'm not planning to port for web player. PC and Mac only.
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    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.
     
  5. akevan

    akevan

    Joined:
    Apr 6, 2013
    Posts:
    10
    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 <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 "


    Not sure how to debug this...
     
  6. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    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.
     
  7. MicroEyes

    MicroEyes

    Joined:
    Jul 3, 2012
    Posts:
    309
    I have some more suggestion.
    1. I think do need to have .a(Dot a) file with DLL. You should probably have that too in Plugins folder.
    2. Please check for API compatibility Level set it to ".Net 2.0"
    3. Port your System to Windows check whether it happens there too.

    Sometimes stupid things might work
     
  8. steinbitglis

    steinbitglis

    Joined:
    Sep 22, 2011
    Posts:
    254
    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.