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

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

An exception of type 'System.DllNotFoundException' occurred in Sodium.dll but was not processed in user code

Additional information: Failed to load DLL 'libsodium.dll': the specified module was not found. (Exception from HRESULT: 0x8007007E)

I'm just trying to run sample code from the gitbooks documentation https://bitbeans.gitbooks.io/libsodium-net/content/password_hashing/index.html

const string PASSWORD = "Correct Horse Battery Staple"; const string SALT = "qa~t](84z<1t<1oz: ik.@IRNyhG =8q(o"; const long OUTPUT_LENGTH = 512; //this will produce a 512 byte hash var hash = PasswordHash.ScryptHashBinary(PASSWORD, SALT, PasswordHash.Strength.Medium, OUTPUT_LENGTH); 
+4
c # dll asp.net-web-api2 libsodium
source share
2 answers

I had the same problem and it was solved with the help of Jorn Wildt's answer given here .

It turns out that ASP.NET does not create shadow copies of unmanaged DLLs such as libsodium.dll and libsodium-64.dll.

Sodium.dll (managed code) is trying to load DLLs from the same directory as the shadow copy of Sodium.dll (which is not going to work), or some of them in the PATH environment variable 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); 

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

+5
source share

I also got this one. The first part of the solution was to do this as @NiklasEkman by adding the directory to the PATH variable.

But I got the same error when deploying in our QA environment. Having spent hours using permissions, trying to find out if the DLLs are in the correct directory and the like, I came across this message: https://mspcontrol.org/forums/topic/add-user-error-unable-to-load- dll-libsodium-64-dll / # post-4765

You need to install Visual C ++ Redistributable for Visual Studio 2015 (13 MB) https://www.microsoft.com/en-us/download/details.aspx?id=48145

In the end, this solved the problem for me.

+5
source share

All Articles