Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

IL2CPP missing native dll referenced by managed library

Discussion in '2018.1 Beta' started by Atair, Apr 21, 2018.

  1. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    I have a NET dll that needs a few other (native) dlls in a subfolder in the same spot. They are all set to be included in the build, and are there, just not with the subfolder

    In 2017.4 i have to manually copy them to a new subfolder in the managed folder, then everything works.

    Now in 2018 and il2cpp i dont know where to put them.

    Not sure if i already missed something in 2017, but i set all dlls to be included (x64 only)

    in the editor everything works fine ( both 2017 and 2018)

    In case it help - the library in question is the Embree.NET wrapper around the Intel Embree raytracing library

    EDIT:
    they are in the Plugins folder, but the library requires them to be in a "x64" subfolder, and however i try i cant seem to get it to work ..

    the net library searches for the dlls like this:
    Code (CSharp):
    1. string fullPath = System.Reflection.Assembly.GetAssembly(typeof(RTC)).Location;
    2. string assebmlyDirectory = Path.GetDirectoryName(fullPath);
    3. string architecture = IntPtr.Size == 8 ? "x64" : "x86";
    4. string dllDirectory = Path.Combine(assebmlyDirectory, architecture);
    5. // Temporarily change working directory and make a call to Embree native code
    6. // to force the dll to load
    7. string previousCurrentDirectory = Directory.GetCurrentDirectory();
    8. Directory.SetCurrentDirectory(dllDirectory);
    So it seems to look for a x64 folder relative to the current dll - that worked in 2017, but how to fix this in 2018?
     
    Last edited: Apr 21, 2018
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    I don't think that anything has changed with respect to IL2CPP between 2017.4 and 2018.1 regarding this case. However, something might be different in Unity that is causing this issue. What error message do you see in 2018.1 which indicates this does not work?
     
  3. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    there is no error message - i just compiled the embree wrapper as is, and whatever exceptions it may encounter - i dont get any errors.
    But something changed between 2017 and 2018 - threr is no managed folder where i can put my dlls..
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    What is the observable difference between Unity versions? Maybe that will help determine the cause of the issue?
     
  5. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    I think there is a misunderstanding - try to clarify:

    2017.4 : Compile with mono - the build has a folder named 'Managed' - there are the Net Dlls. here i put my native dlls manually (after the build) inside a new 'x64' folder, so my managed embree dll can find them. It cant find them in the plugins - i guess because of the code in the fist post.

    2018.1: Compile with IL2CPP - there is no managed folder anymore. I dont know where to put my native dlls for embree. It cant find them in the plugins folder (as before).

    the observable difference is that i dont get any image - so to speak.. and i guess it is because my embree.dll (managed) cant find the native dlls to initialize. The program does not crash.
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Ok, that makes more sense.

    For Mono, the managed assemblies are delivered to the player and just-in-time (JIT) compiled on the device running the player. So your embree dll worked like that.

    For IL2CPP, the managed assemblies are (ahead-of-time) AOT compiled on the machine running the Unity editor, and are never delivered to the device.

    Rather than manually putting the files in the Managed directory, you can use the Managed Plugin process: https://docs.unity3d.com/Manual/UsingDLL.html

    Then they should get AOT compiled by IL2CPP.
     
    Atair likes this.
  7. Atair

    Atair

    Joined:
    Oct 16, 2015
    Posts:
    42
    cool will try that - thanks!