Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Adding existing dlls for 3rd parties to Unity project

Discussion in 'VR' started by CharlieBrown, Apr 1, 2016.

  1. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    Hi,
    I am including in Assets folder some dll for working with Hololens. I understand that even working with Unity framework, Unity should be able to handle new frameworks dlls for external parties due to the final app will be an Universal App. Everytime that I place a new dll, this faults appears. I need this when programming Unity before "building " the final app for VisualStudio so its not possible to add it when running with VisualStudio in the second stage.
    Any idea?

    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
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    I suppose this DLL is targeting .NET Core? While you can use it on HoloLens, Unity editor supports only .NET 3.5 DLLs, anything high will result in such exceptions. You need to click on the DLL and mark it to be incompatible with Unity editor, and only compatible with Windows Store. That way, the editor will not load the DLL, but will include it into your project when you build it.

    If you want to reference that DLL from scripts, you'll have to wrap all the code in #if NETFX_CORE/#endif, so that the consumer code does not get compiled when building scripts for the editor.
     
    CharlieBrown likes this.
  3. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    Hi Tautvydas,

    I try to use a robotics dll ( an already existing dll targeting .Net framework 4.5), I cannot compile it .net framework 3.5.due to I am not have the source code it comes from an existing SDK. I try to share an already existing class in this comercial software to Unity so in Unity I have all the information of this software, I just communicate both devices ( Hololens and this comertial software) so both have to "understand" this class. My case is that I want to reference this dll from scripts.The issue is that I need that Unity "understand" different objects and avoid making my own protocol manually(takes a lot of time due to this class is huge). If I wrap it, I am not sure if unity will be able to understand this object and work with them. So if I place it in my asset folder I have the message above
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
  5. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    I am getting started in Unity( I am a c#developer that uses Visual Studio) not Unity. Nevertheless I want to use this scripts inside Unity before compiling for making the Visual Studio application(universal app). I would like to test it in Unity not in VisualStudio due to the complexity of working with the emulator and rebuilding application multiple times. I have seen multiple posts and the answer is not as trivial as you say....There is not a concrete answer to this, people speaks about wrapper dlls, using "unmanaged export " so I think unity is not prepared yet for what I try to do.
     
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,646
    You cannot run that DLL code in the editor: Unity Editor simply doesn't support higher than .NET 3.5 at this point in time.
     
  7. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    Well, so it makes difficult working with all the power of Universal Apps( framework above 3.5).Should I add it after making my VS application?
     
  8. CharlieBrown

    CharlieBrown

    Joined:
    May 11, 2015
    Posts:
    10
    Unity uses a subset of .Net framework 3.5 (Mono .Net). However you can target UWP apps and use the .Net compiler to compile for .Net 4.5, just be warned it's not cross platform at this point. Its possible to use the NET_FX_CORE and WINDOWS_UWP defines, in your cs scripting files. After you've compiled your applications in Unity and generated the cs project files, you're free to continue added what ever logic you need as long as it follows the UWP contracts.

    Another note, if you need to use some raw level api's that even unity doesn't support you may want to look at the IL2CPP scripting engine, this produces DirectX and C++ projects which you can further take and expand upon with the Hololens framework.