gpt4 book ai didi

c# - Libsodium-net - 无法加载 DLL 'libsodium.dll

转载 作者:太空狗 更新时间:2023-10-29 19:55:40 24 4
gpt4 key购买 nike

我通过 NuGet 安装了 Libsodium-net 并且能够在我的类中包含 Sodium,但是当我尝试运行它时,我得到了

Sodium.dll 中发生了“System.DllNotFoundException”类型的异常,但未在用户代码中处理

附加信息:无法加载 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);

最佳答案

我遇到了同样的问题并使用 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);

正如鲁本对答案的评论;我在 Global.asaxApplication_Start 方法中添加了上述代码。

关于c# - Libsodium-net - 无法加载 DLL 'libsodium.dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37347620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com