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

DllNotFoundException caused by presence of DllMain

Discussion in 'Editor & General Support' started by iko79, Jan 19, 2016.

  1. iko79

    iko79

    Joined:
    Jan 21, 2013
    Posts:
    45
    Hi,

    as so many people (including myself) appear to frequently have a hard time with getting native plugins to work, I'm posting this new insight here: As I just found out after quite some trial&error investigation, you're not supposed to have a DllMain in your dll code. If you do, even if it is empty, Unity will be unable to load the dll and you'll get meaningless errors such as:

    D:\UnityPlayground\Assets\Plugins\x86_64\MyPlugin.dll
    Failed to load 'Assets/Plugins/x86_64/MyPlugin.dll' with error 'Der Vorgang wurde erfolgreich beendet.
    ', GetDllDirectory returned ''. If GetDllDirectory returned non empty path, check that you're using SetDirectoryDll correctly.

    DllNotFoundException: Assets/Plugins/x86_64/MyPlugin.dll
    at (wrapper managed-to-native) MyInterface:SetTimeFromUnity (single)
    at MyInterface+<CallPluginAtEndOfFrames>c__Iterator1.MoveNext () [0x00038] in D:\UnityPlayground\Assets\Scripts\MyInterface.cs:62


    A note for non-german-speakers: "Der Vorgang wurde erfolgreich beendet." translates as "The operation completed successfully."

    At this point, I'd like to stress that getting plugins to work is a highly tedious and frustrating experience almost every time, and I hope the Unity devteam finds some time to simplify this. Getting meaningful error messages would be a good start, since we usually end up randomly copying dlls and their dependencies across our system until it all of a sudden works in a configuration we already tried before and we're left clueless.

    Cheers,
    iko79