Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet core in macOS: "The type initializer for 'Crypto' threw an exception"

I followed the instructions on the .NET Core website, but got this error. Apparently there are some pre-reqs which are missing. Any idea how to install those?

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
like image 842
Naveen Vijay Avatar asked Aug 24 '16 21:08

Naveen Vijay


People also ask

How does cryptography work in NET Core and NET 5?

Cryptographic operations in .NET Core and .NET 5 are done by operating system (OS) libraries. This dependency has advantages: .NET apps benefit from OS reliability. Keeping cryptography libraries safe from vulnerabilities is a high priority for OS vendors. To do that, they provide updates that system administrators should be applying.

How to manage certificates in the macOS keychain?

ASP.NET Core, macOS, and certificates .NET provides the ability to manage certificates in the macOS Keychain with the System.Security.Cryptography.X509Certificatesclass. Access to the macOS Keychain uses the applications identity as the primary key when deciding which partition to consider.

How do I set DotNet_root in the terminal?

If you install the .NET SDK, you will not need to install the corresponding runtime: Next, extract the downloaded file and use the export command to set DOTNET_ROOT to the extracted folder's location and then ensure .NET is in PATH. This should make the .NET CLI commands available at the terminal.

Is Windows CryptoAPI capable of PKCS1 signature with SHA-2 algorithm?

* Windows CryptoAPI (CAPI) is capable of PKCS1 signature with a SHA-2 algorithm. But the individual RSA object may be loaded in a cryptographic service provider (CSP) that doesn't support it. Windows CryptoAPI (CAPI) is used whenever new RSACryptoServiceProvider () is used.


2 Answers

The install instructions for macOS are out of date. See this discussion on Github: SSL Fails to Link Using Brew.

I ran into this myself when installing .NET Core on macOS El Capitan. The solution, from this answer, is running 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 running that command in my terminal, dotnet new worked fine.

like image 136
Nate Barbettini Avatar answered Nov 15 '22 07:11

Nate Barbettini


Something happened with my brew install 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/ 
like image 34
Sir CodesALot Avatar answered Nov 15 '22 07:11

Sir CodesALot