问题
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
回答1:
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.
回答2:
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/
回答3:
Need to specify where the required file is located 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
Above solution will work if you having the same folder structure for installed dotnet core.
/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.0/System.Security.Cryptography.Native.dylib
kindly check the location of the file System.Security.Cryptography.Native.dylib in your system, however folder structure or packages may get change as per the updates. In my case the path was
/usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.0.2/System.Security.Cryptography.Native.dylib
来源:https://stackoverflow.com/questions/39133356/dotnet-core-in-macos-the-type-initializer-for-crypto-threw-an-exception