MacOS dotnet kernel: "Type initializer for" Crypto "throws an exception"

I followed the instructions on the .NET Core site , but got this error. There are apparently some preliminary requirements that are missing. Any idea how to install them?

mymac:~ naveen.vijay$ dotnet new Unhandled Exception: System.TypeInitializationException: The type initializer for 'Crypto' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native': The specified module could not be found. (Exception from HRESULT: 0x8007007E) at Interop.CryptoInitializer.EnsureOpenSslInitialized() at Interop.CryptoInitializer..cctor() --- End of inner exception stack trace --- at Interop.Crypto..cctor() --- End of inner exception stack trace --- at Interop.Crypto.GetRandomBytes(Byte* buf, Int32 num) at System.IO.Path.GetCryptoRandomBytes(Byte* bytes, Int32 byteCount) at System.IO.Path.GetRandomFileName() at Microsoft.DotNet.InternalAbstractions.TemporaryDirectory..ctor() at Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateTemporaryDirectory() at Microsoft.DotNet.Configurer.NuGetPackagesArchiver..ctor() at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel) at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient) at Microsoft.DotNet.Cli.Program.Main(String[] args) Abort trap: 6 
+5
source share
3 answers

Installation instructions for macOS are out of date. See this discussion on Github: SSL cannot be bound using Brew .

I came across this myself when installing .NET Core on macOS El Capitan. The solution, from this answer , does the following:

 sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib 

After executing this command in my terminal dotnet new worked fine.

+8
source

Something happened with my brew installation, and I had to run the following commands to create symbolic links to OpenSSL (from the .Net Core page on Microsoft ):

 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/ 
+6
source

You must specify where the file is located in order to map the path

sudo install_name_tool -add_rpath / usr / local / opt / openssl / lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib

The above solution will work if you have the same folder structure for the installed dotnet kernel.

/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib

kindly check the location of the System.Security.Cryptography.Native.dylib file on your system, however, the folder structure or packages may receive changes in accordance with the updates. In my case, the path was

/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.2/System.Security.Cryptography.Native.dylib

+2
source

All Articles