How to include libsodium.net on ASP.NET

后端 未结 2 1134
礼貌的吻别
礼貌的吻别 2020-12-06 17:50

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

相关标签:
2条回答
  • 2020-12-06 18:08

    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:

    // 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);
    

    Update January 2018 (from Jordan Rieger's answer):

    Note that you may also need to install the Microsoft Visual C++ 2015 Redistributable on your server (either the x64 or x86 target, depending on your process.)

    Don't forget to restart your app pool (I did an IIS reset) after installing the redistributable.

    0 讨论(0)
  • 2020-12-06 18:22

    Note that you may also need to install the Microsoft Visual C++ 2015 Redistributable on your server (either the x64 or x86 target, depending on your process.)

    Don't forget to restart your app pool (I did an IIS reset) after installing the redistributable.

    See my comment on https://stackoverflow.com/a/45078280/284704.

    0 讨论(0)
提交回复
热议问题