Libsodium-net - 无法加载 DLL 'libsodium.dll
Libsodium-net - Unable to load DLL 'libsodium.dll
我通过 NuGet 安装了 Libsodium-net 并且能够在我的 类 中包含 Sodium,但是当我尝试 运行 它时,我得到
'System.DllNotFoundException' 类型的异常发生在 Sodium.dll 中,但未在用户代码中处理
附加信息:无法加载 DLL 'libsodium.dll':找不到指定的模块。 (HRESULT 异常:0x8007007E)
我只是想 运行 gitbooks 文档中的示例代码
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);
我遇到了同样的问题并使用 解决了它。
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);
正如鲁本对答案的评论;我在 Global.asax
.
的 Application_Start
方法中添加了上面的代码
我也收到了这个。解决方案的第一部分是像@NiklasEkman 那样做,将目录添加到 PATH 变量。
但是,当部署到我们的 QA 环境时,我遇到了完全相同的错误。在花了几个小时弄乱权限后,试图弄清楚 dll 是否在正确的目录中,类似的我 运行 进入这个 post:
https://mspcontrol.org/forums/topic/add-user-error-unable-to-load-dll-libsodium-64-dll/#post-4765
You have to install Visual C++ Redistributable for Visual Studio 2015 (13 Mb)
https://www.microsoft.com/en-us/download/details.aspx?id=48145
最终为我解决了这个问题。
我通过 NuGet 安装了 Libsodium-net 并且能够在我的 类 中包含 Sodium,但是当我尝试 运行 它时,我得到
'System.DllNotFoundException' 类型的异常发生在 Sodium.dll 中,但未在用户代码中处理
附加信息:无法加载 DLL 'libsodium.dll':找不到指定的模块。 (HRESULT 异常:0x8007007E)
我只是想 运行 gitbooks 文档中的示例代码 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);
我遇到了同样的问题并使用
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);
正如鲁本对答案的评论;我在 Global.asax
.
Application_Start
方法中添加了上面的代码
我也收到了这个。解决方案的第一部分是像@NiklasEkman 那样做,将目录添加到 PATH 变量。
但是,当部署到我们的 QA 环境时,我遇到了完全相同的错误。在花了几个小时弄乱权限后,试图弄清楚 dll 是否在正确的目录中,类似的我 运行 进入这个 post: https://mspcontrol.org/forums/topic/add-user-error-unable-to-load-dll-libsodium-64-dll/#post-4765
You have to install Visual C++ Redistributable for Visual Studio 2015 (13 Mb) https://www.microsoft.com/en-us/download/details.aspx?id=48145
最终为我解决了这个问题。