如何包括ASP.NET libsodium.net

编程入门 行业动态 更新时间:2024-10-18 19:23:23
本文介绍了如何包括ASP.NET libsodium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个ASP.NET web服务旧建(使用的.asmx)文件。我需要使用sodium - 不幸的是它在加载依赖l​​ibsodium.dll文件失败。什么我做了错误的任何想法?

I have an old webservice build on ASP.NET (using .asmx) files. I need to use sodium - unfortunately it fails while loading the dependent libsodium.dll file. Any ideas about what I make wrong?

  • 我走过的NuGet添加libsodium。

  • I have added libsodium through NuGet.

我已经改名为64位DLL为libsodium.dll(和其他命名约定太)。

I have renamed the 64 bit DLL to "libsodium.dll" (and other naming conventions too).

我曾尝试libsodium.dll直接引用,但VS拒绝它(不是一个有效的DLL)。所以我将它称为内容,而不是与复制到输出。

I have tried to reference libsodium.dll directly but VS rejects it (not a valid DLL). So I have added it as "content" instead with "copy to output".

建筑,我可以看到该网站/ bin文件夹包含sodium.dll(.NET程序集),并libsodium后。

After building I can see that the website/Bin folder contains both sodium.dll (the .NET assembly) and libsodium.

当我尝试使用libsodium我得到:

When I try to use libsodium I get:

错误2015年2月2日11:14:27118 13798ms [41] CabinetService doRequest - 捉住:为Sodium.SodiumCore'的类型初始值引发了异常。System.TypeInitializationException:对于Sodium.SodiumCore'的类型初始值引发了异常。 ---> System.DllNotFoundException:无法加载DLLlibsodium.dll:指定的模块找不到。 (异常来自HRESULT:0x8007007E)   在DynamicDllInvokeType.sodium_init()   在Sodium.SodiumCore..cctor()   ---内部异常堆栈跟踪的结尾---   在Sodium.SodiumCore.LibraryName()   在Sodium.SecretBox.Create(字节[]消息,字节[]的随机数,字节[]键)   在Macaroons.SecretBoxCryptoAlgorithm.Encrypt(字节[]键,字节[]明文)在C:\\项目\\ Macaroons.Net \\ Macaroons.Net \\ SecretBoxCryptoAlgorithm.cs:58行

ERROR 2015-02-02 11:14:27,118 13798ms [41] CabinetService doRequest - Caught: The type initializer for 'Sodium.SodiumCore' threw an exception. System.TypeInitializationException: The type initializer for 'Sodium.SodiumCore' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'libsodium.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at DynamicDllInvokeType.sodium_init() at Sodium.SodiumCore..cctor() --- End of inner exception stack trace --- at Sodium.SodiumCore.LibraryName() at Sodium.SecretBox.Create(Byte[] message, Byte[] nonce, Byte[] key) at Macaroons.SecretBoxCryptoAlgorithm.Encrypt(Byte[] key, Byte[] plainText) in c:\Projects\Macaroons.Net\Macaroons.Net\SecretBoxCryptoAlgorithm.cs:line 58

所以它不能找到libsodium.dll,即使是在Bin文件夹。我也尝试删除的sodium里后,我得到了一个运行时错误的依赖性说:sodium丢失 - 当我重新添加它,该错误消失了,我得到了一个以上的,而不是(指示sodium正确加载)。

So it cannot find "libsodium.dll" even though it is in the Bin folder. I did also try to remove the dependency on "sodium" where after I got a runtime error saying "sodium" is missing - when I re-added it, that error disappeared and I got the one above instead (indicating the "sodium" loads correctly).

于是我在打开网页的影子文件夹C:\\ WINDOWS \\ Microsoft.NET \\框架\\ v4.0.30319 \\临时ASP.NET文件\\ cabinetservice并搜索钠。唯一的结果就是在一些子文件夹sodium.dll。没有libsodium.dll。

So I open up the website shadow folder in "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\cabinetservice" and search for "sodium". The only result is "sodium.dll" in some subfolder. There is no "libsodium.dll".

因此​​很明显,创建该网站的卷影副本时ASP.NET忽略libsodium.dll文件。

So apparently ASP.NET ignores the "libsodium.dll" file when creating the shadow copy of the website.

我也试图加入libsodium.dll(32位)到C:\\ Windows \\ System32下和libsodium.dll(64位)到C:\\ WINDOWS \\ SysWOW64中。同样的结果。

I have also tried adding the libsodium.dll (32 bit) to C:\Windows\System32 and libsodium.dll (64 bit) to C:\Windows\SysWOW64. Same result.

我试图C:\\ WINDOWS \\ Microsoft.NET \\装配\\ GAC_32 \\ libsodium和C:\\ WINDOWS \\ Microsoft.NET \\装配\\ GAC_64 \\ libsodium。同样的结果。

And I have tried C:\Windows\Microsoft.NET\assembly\GAC_32\libsodium and C:\Windows\Microsoft.NET\assembly\GAC_64\libsodium. Same result.

我怎样才能让ASP.NET知道依赖?

How can I make ASP.NET aware of the dependency?

推荐答案

原来,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(托管code)试图从任一相同的目录Sodium.dll的卷影副本(这是行不通的)加载的DLL - 或一些地方在PATH环境变量的目录

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.

我的解决方案是之前调用任何钠code添加的AppDomain \\ bin目录的路径:

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

// Make it possible to load unmanaged libsodium DLLs that .NET does not make shadow copies of. // -> Simply point the "path" variable to the Bin directory. string path = Environment.GetEnvironmentVariable("PATH"); string binDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bin"); Environment.SetEnvironmentVariable("PATH", path + ";" + binDir);

更多推荐

如何包括ASP.NET libsodium.net

本文发布于:2023-11-08 20:16:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   ASP   net   libsodium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!