Unable to load DLL "System.Security.Cryptography.Native.OpenSsl" when creating a new HttpClient

I am working with a .net kernel and must make an HTTP call on my server.
The code used is as follows:

try { var client = new HttpClient (); var helloUri = new System.Uri (string.Concat ("http://localhost:1234", "/hello")); var response = client.GetAsync (helloUri); var helloReponse = response.Result; return helloReponse.StatusCode == System.Net.HttpStatusCode.OK; } catch (System.Exception e) { throw e; } 

I am creating a publishing package with the specified runtime (osx10.12-x64 in my case). When working with osx, I have this error:

 (The type initializer for 'System.Net.Http.CurlHandler' threw an exception.) ---> System.TypeInitializationException: The type initializer for 'System.Net.Http.CurlHandler' threw an exception. ---> System.TypeInitializationException: The type initializer for 'Http' threw an exception. ---> System.TypeInitializationException: The type initializer for 'HttpInitializer' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found. 

My publication folder contains "System.Security.Cryptography.Native.OpenSsl.dylib"

This link ( https://github.com/dotnet/cli/issues/5129 ) told me how to solve the problem on my machine.

How can I do this on a client machine that does not have dotnet?

+7
source share
3 answers

System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found. almost always means "I can't find OpenSSL" (libcrypto.1.0.0.dylib / libssl.1.0.0.dylib).

There are three main workarounds.

  • You have your client, following .NET Core for macOS prerequisites from https://www.microsoft.com/net/core#macos :

     $ brew update $ brew install openssl $ mkdir -p /usr/local/lib $ ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/ $ ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/ 
  • If you made a standalone build, you can take libcrypto.1.0.0.dylib and libssl.1.0.0.dylib and copy them to your application directory.

    • Technically, they should be in the same directory as System.Security.Cryptography.Native.OpenSsl.dylib.
    • Be careful with this as you distribute the security component. Your local copy will outperform the system installation copy, so you will have to reissue it after any release of OpenSSL security.
  • Wait a bit for .NET Core 2.0, because OpenSSL is no longer the main dependency on macOS ( https://github.com/dotnet/corefx/issues/9394 ).
+11
source

The solution that worked for me was the second one suggested by @bartonjs.

I had to change my libssl.dylib since it was referencing libcrypto with an absolute path.

 otool -l libssl.1.0.0.dylib showed the absolute path install_name_tool -change usr/../Cellar/.. @rpath/libcrypto.1.0.0.dylib libssl.1.0.0.dylib to change the path 
+3
source

Yes, I solved this problem using NetCore 2.2 instead of NetCore 1.1.2

You can download and install it from

https://github.com/dotnet/core/blob/master/release-notes/2.2/2.2.1/2.2.1-download.md

0
source

Source: https://habr.com/ru/post/1267356/


All Articles