alpine arm64 与 e_sqlite3' or one of its dependencies 异常解决方法 返回

SqlSugar
1 576

Microsoft 官方的 Docker 镜像不能直接运行 EFCore,会出现异常:

      System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
       ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
       ---> System.DllNotFoundException: Unable to load shared library 'e_sqlite3' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libe_sqlite3: No such file or directory
         at System.Runtime.InteropServices.NativeLibrary.LoadByName(String libraryName, QCallAssembly callingAssembly, Boolean hasDllImportSearchPathFlag, UInt32 dllImportSearchPathFlag, Boolean throwOnError)
         at System.Runtime.InteropServices.NativeLibrary.LoadLibraryByName(String libraryName, Assembly assembly, Nullable`1 searchPath, Boolean throwOnError)
         at System.Runtime.InteropServices.NativeLibrary.Load(String libraryName, Assembly assembly, Nullable`1 searchPath)
         at SQLitePCL.NativeLibrary.Load(String libraryName, Assembly assy, Int32 flags)
         at SQLitePCL.Batteries_V2.MakeDynamic(String name, Int32 flags)
         at SQLitePCL.Batteries_V2.DoDynamic_cdecl(String name, Int32 flags)
         at SQLitePCL.Batteries_V2.Init()
         --- End of inner exception stack trace ---
         at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
         at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
         at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
         at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
         at Microsoft.Data.Sqlite.SqliteConnection..cctor()

file

我们在 Linux 中,打开程序目录的 runtimes 中,找到 linux-arm64 目录,执行 ldd 命令,检测 .so 文件的依赖:

 ldd libe_sqlite3.so
        /lib/ld-musl-aarch64.so.1 (0xffffa9187000)
        libc.so.6 => /lib/ld-musl-aarch64.so.1 (0xffffa9187000)
Error loading shared library ld-linux-aarch64.so.1: No such file or directory (needed by libe_sqlite3.so)
Error relocating libe_sqlite3.so: __memcpy_chk: symbol not found
Error relocating libe_sqlite3.so: __memset_chk: symbol not found

发现 缺少 libc 库,可执行以下命令安装:

 apk add libc6-compat

重启程序或容器,即可正常使用。
file

 


热忱回答1

  • 我也遇到这个问题了,我是用直连的方式,没有用ef,


    time:2024-04-23 14:41:14,Request Url:/10/284/1693.jpg,RequestMethod:GET,Parameters:,error:The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.

          System.TypeInitializationException: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.

           ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

           ---> System.DllNotFoundException: Unable to load shared library 'e_sqlite3' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Error loading shared library libe_sqlite3: No such file or directory

             at SQLitePCL.SQLite3Provider_e_sqlite3.NativeMethods.sqlite3_libversion_number()

             at SQLitePCL.SQLite3Provider_e_sqlite3.SQLitePCL.ISQLite3Provider.sqlite3_libversion_number()

             at SQLitePCL.raw.SetProvider(ISQLite3Provider imp)

             at SQLitePCL.Batteries_V2.Init()

             --- End of inner exception stack trace ---

             at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

             at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

             at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)

             at Microsoft.Data.Sqlite.SqliteConnection..cctor()

             --- End of inner exception stack trace ---

             at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)


    发现 缺少 libc 库,重启,也不管用。

    image.png

    没有更好的解决办法,

    0 回复