【问题标题】:TypeInitializationException / SSL library issue with dotnet core and Ubuntudotnet core 和 Ubuntu 的 TypeInitializationException / SSL 库问题
【发布时间】:2021-04-16 09:59:18
【问题描述】:

我有一个 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()

我已经搜索过这个错误,但大部分讨论是从 2016 年开始的。

我正在使用 Ubuntu 20.04

系统信息:

$ 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

如何运行这个应用程序?


更新,我跑了sudo apt-get install lsb-core

它仍然不起作用,但 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

相关,但 macOS dotnet core in macOS: "The type initializer for 'Crypto' threw an exception"

【问题讨论】:

  • consider setting the LD_DEBUG environment variable你做到了吗?
  • @mjwills 这将有助于显示尝试的搜索路径,但不能解决问题。
  • 设置的时候发生了什么?
  • @mjwills 它仍然崩溃但显示更多诊断信息
  • askubuntu.com/a/230773 修复了吗?

标签: c# .net linux .net-core


【解决方案1】:

一个 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 2015-08-04
    • 2019-02-12
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多