macOS中的dotnet核心:“'加密'的类型初始化程序引发异常”

时间:2016-08-24 21:32:35

标签: .net macos .net-core

我按照.NET Core website上的说明操作,但出现了此错误。显然有一些预先要求缺失。知道如何安装这些吗?

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

3 个答案:

答案 0 :(得分:9)

macOS的安装说明已过期。请参阅Github上的讨论:SSL Fails to Link Using Brew

我在macOS El Capitan上安装.NET Core时遇到了这个问题。来自this answer的解决方案正在执行以下操作:

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

在我的终端中运行该命令后,dotnet new工作正常。

答案 1 :(得分:6)

我的brew安装发生了一些事情,我必须运行以下命令来创建指向OpenSSL的符号链接(来自Microsoft上的.Net Core页面):

io_service.run()

答案 2 :(得分:2)

需要指定所需文件的位置以映射路径

  

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

如果安装的dotnet核心具有相同的文件夹结构,则上述解决方案将起作用。

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

请在系统中检查文件 System.Security.Cryptography.Native.dylib 的位置,但文件夹结构或包可能会根据更新进行更改。在我的情况下,路径是

  

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