简体   繁体   中英

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 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.

I am using 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 .

It still does not work, but lsb_release -a is now different:

$ 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"

A hacky solution is to copy the 5.x libraries into 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM