Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl' when creating new HttpClient
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.
- Technically, they need to be in the same directory as System.Security.Cryptography.Native.OpenSsl.dylib.
- Be careful with this, since you're distributing a security component. Your local copy will trump a system installation copy, so you'll need to republish after any OpenSSL security releases.
- You wait a little bit for .NET Core 2.0, because OpenSSL is no longer a primary dependency on macOS (https://github.com/dotnet/corefx/issues/9394).
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