Libsodium-net-无法加载DLL'libsodium.dll [英] Libsodium-net - Unable to load DLL 'libsodium.dll
问题描述
我通过NuGet安装了Libsodium-net,并且可以将Sodium包含在我的课程中,但是当我尝试运行它时,我得到了
I installed Libsodium-net through NuGet and am able to include Sodium in my classes, but when I try to run it, I get
System.DllNotFoundException'发生在Sodium.dll中,但未在用户代码中处理
An exception of type 'System.DllNotFoundException' occurred in Sodium.dll but was not handled in user code
其他信息:无法加载DLL libsodium.dll:指定模块无法找到了。 (来自HRESULT的异常:0x8007007E)
Additional information: Unable to load DLL 'libsodium.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
我只是尝试运行gitbooks文档
https://bitbeans.gitbooks.io/libsodium-net/content/password_hashing/index.html
I am just trying to run the 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);
推荐答案
I had the same problem and solved it using Jørn Wildt's answer given here.
事实证明,ASP .NET不会对非托管DLL(例如libsodium.dll和libsodium-64.dll)进行卷影副本。
It turns out that ASP.NET doesn't make shadow copies of unmanaged DLLs such as libsodium.dll and libsodium-64.dll.
Sodium.dll(托管代码)尝试加载来自与Sodium.dll的卷影副本相同的目录中的DLL(将不起作用)-或PATH环境变量目录中的某些目录中的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.
我的解决方案是在调用任何钠代码之前将AppDomain \Bin目录添加到路径:
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);
如鲁本对答案的评论;我在 Global.asax
的 Application_Start
方法中添加了上面的代码。
As Reuben commented on the answer; I added the above code in my Application_Start
method of my Global.asax
.
这篇关于Libsodium-net-无法加载DLL'libsodium.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!