I'm working with .net core and need to execute a http call to my server.
The code used is as follow :
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 create the publish package with the runtime specified (osx10.12-x64 in my case). When working on 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 publish folder contain the "System.Security.Cryptography.Native.OpenSsl.dylib"
This link (https://github.com/dotnet/cli/issues/5129) told me how to solve the problem in my machine.
How can I do this in a customer's machine which do not have dotnet?
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 major workarounds.
You have your customer follow the .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 have done a standalone build you can take the libcrypto.1.0.0.dylib and libssl.1.0.0.dylib and copy them into your application directory.
The solution that worked for me was the second proposed by @bartonjs.
I had to modify my libssl.dylib since she referenced 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With