Libsodium-net - Unable to load DLL 'libsodium.dll

后端 未结 2 429
迷失自我
迷失自我 2021-01-05 06:21

I installed Libsodium-net through NuGet and am able to include Sodium in my classes, but when I try to run it, I get

An exception of type \'System.DllNotFoundExcepti

2条回答
  •  天命终不由人
    2021-01-05 06:30

    I had the same problem and solved it using Jørn Wildt's answer given here.

    It turns out that ASP.NET doesn't make shadow copies of unmanaged DLLs such as libsodium.dll and libsodium-64.dll.

    Sodium.dll (the managed code) tries to load the DLLs from either the same directory as the shadow copy of Sodium.dll (which is not going to work) - or some where in the PATH environment variable's directories.

    My solution was to add the AppDomain \Bin directory to the path before calling any Sodium code:

    string path = Environment.GetEnvironmentVariable("PATH");
    string binDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bin");
    Environment.SetEnvironmentVariable("PATH", path + ";" + binDir);
    

    As Reuben commented on the answer; I added the above code in my Application_Start method of my Global.asax.

提交回复
热议问题