Search Unity

Problem with c# dlls

Discussion in 'Scripting' started by handsomePATT, Mar 1, 2012.

  1. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    Hey ive been trying to put my code into a DLL and am having some problems. No matter which DLL i bring into Unity I get the same error

    Code (csharp):
    1. Internal compiler error. See the console log for more information. output was:
    2. Unhandled Exception: System.TypeLoadException: Could not load type 'System.Runtime.Versioning.TargetFrameworkAttribute' from assembly 'TestDLL'.
    all that is in this dll is

    Code (csharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5.  
    6. namespace TestDLL
    7. {
    8.     public class TestClass
    9.     {
    10.         public bool ReturnTrue()
    11.         {
    12.             return true;
    13.         }
    14.     }
    15. }
    I dont see why this wont work. It works when i use the DLL in other projects in visual studio. Is this a Unity problem? I have Unity Pro.
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I ran into some issues including System.Linq in a DLL. Does removing that reference resolve it?
     
  3. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    No i tried deleting all of the references and using statements but still get the same error.
     
  4. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    I was playing around and started a brand new Unity project and dragged in my DLL and it worked! But when I created a new c# script, I got that error. I dont try to reference the DLL at all in my script yet, its just a default new Unity Script and i get that error. Any ideas why that would happen?
     
  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Change your target framework to 2.0, nothing higher and then simply remove the using statement for Linq, wala will work
     
  6. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    awesome thanks haha i knew it was something stupid like that
     
  7. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    Is there anything that works in 2.0 which doesn't work in 3.5?

    In my experience so far, 3.5 is fine, so long as you avoid library features that aren't supported. You find out pretty quickly which ones they are, and I always got the impression they just didn't exist in 2.0.

    There are quite a few things in 2.0 that won't work in Unity too, at least in some contexts (e.g. Xbox, iOS, webplayer), so you still need to be ready to avoid them.
     
  8. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    It's not 2.0 that is a problem, it was the version of Mono, you have to review the methods in Mono to determine if you can use them in Unity, just because it is in the Microsoft framework has no bearing as to if it will work or not, it has to exist in Mono or the version of Mono that Unity is using which all of it is based off 2.0 core, some improvements to handle a little more but always refer back to Mono.
     
  9. handsomePATT

    handsomePATT

    Joined:
    Nov 30, 2010
    Posts:
    574
    I got it working by switching to 3.5 client edition so I think thats fine
     
  10. Murcho

    Murcho

    Joined:
    Mar 2, 2009
    Posts:
    309
    Came across this thread while searching for the OP's issue myself. I can confirm that switching the build profile to 3.5 client edition gets rid of the compile issues inside of Unity (version 3.5)