[英]TypeInitializationException / SSL library issue with dotnet core and Ubuntu
I have a dotnet core app ( netcoreapp3.1
) that crashes with the following error on launch:我有一个 dotnet 核心应用程序 (
netcoreapp3.1
) 在启动时崩溃并出现以下错误:
$ dotnet run
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 shared library 'libSystem.Security.Cryptography.Native.OpenSsl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibSystem.Security.Cryptography.Native.OpenSsl: cannot open shared object file: No such file or directory
at Interop.CryptoInitializer.EnsureOpenSslInitialized()
at Interop.CryptoInitializer..cctor()
--- End of inner exception stack trace ---
at Interop.CryptoInitializer.Initialize()
at Interop.Crypto..cctor()
--- End of inner exception stack trace ---
at Interop.Crypto.EvpPkeyDestroy(IntPtr pkey)
at System.Security.Cryptography.SafeEvpPKeyHandle.ReleaseHandle()
at System.Runtime.InteropServices.SafeHandle.InternalRelease(Boolean disposeOrFinalizeOperation)
at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing)
at System.Runtime.InteropServices.SafeHandle.Finalize()
I have searched for this error, but most of the discussion is from 2016.我已经搜索过这个错误,但大部分讨论都是从 2016 年开始的。
I am using Ubuntu 20.04 .我正在使用Ubuntu 20.04 。
System info:系统信息:
$ openssl version
OpenSSL 1.0.2n 7 Dec 2017
$ dotnet --version
5.0.101
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: foca
How can I run this application?我怎样才能运行这个应用程序?
Update, I ran sudo apt-get install lsb-core
.更新,我跑了
sudo apt-get install lsb-core
。
It still does not work, but lsb_release -a
is now different:它仍然不起作用,但
lsb_release -a
现在不同了:
$ lsb_release -a
LSB Version: core-11.1.0ubuntu2-noarch:security-11.1.0ubuntu2-noarch
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
Related, but macOS dotnet core in macOS: "The type initializer for 'Crypto' threw an exception"相关,但 macOS 中的 macOS dotnet 核心:“'Crypto' 的类型初始化程序引发异常”
A hacky solution is to copy the 5.x
libraries into 3.x
:一个 hacky 解决方案是将
5.x
库复制到3.x
中:
sudo cp /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.2/libSystem.Security.Cryptography.Native.OpenSsl.a /usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.11/libSystem.Security.Cryptography.Native.OpenSsl.a
sudo cp /usr/share/dotnet/shared/Microsoft.NETCore.App/5.0.2/libSystem.Security.Cryptography.Native.OpenSsl.so /usr/share/dotnet/shared/Microsoft.NETCore.App/3.1.11/libSystem.Security.Cryptography.Native.OpenSsl.so
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.