Ask questionsException when creating SQLite DB in when targetting osx-arm64 / .Net 6 (preview)

I'm using a SQLite provider with .Net 6.0 preview 1, and EFCore 6.0, targetting Apple Silicon (osx-arm64). When the DB creation is attempted, the following exception is thrown:

Exception: The type initializer for 'Microsoft.Data.Sqlite.SqliteConnection' threw an exception.
Unhandled 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 DYLD_PRINT_LIBRARIES environment variable: dlopen(libe_sqlite3, 1): image not found
   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.MethodBase.Invoke(Object obj, Object[] parameters)
   at Microsoft.Data.Sqlite.Utilities.BundleInitializer.Initialize()
   at Microsoft.Data.Sqlite.SqliteConnection..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Data.Sqlite.SqliteConnection..ctor(String connectionString)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteRelationalConnection.CreateDbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnection()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.get_DbConnectionState()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists()
   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabaseCreator.EnsureCreated()
   at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()

Discussed this with Rich Lander, and concluded that it's likely to be because the native/unmanaged SQLite libraries can't be loaded because they're x64, not arm64.

The project where this happens is here: - I will try and create a small standalone repro project if I get time.

EF Core version: 6.0.100-preview.1.21103.13 Database provider: SQLite Target framework: 6.0.100-preview.1.21103.13 Operating system: OSX 11.3 Beta (20E5172i) Hardware: Apple MacBook Pro M1 IDE: Visual Studio for Mac 8.9 build 1593


Answer questions ericsink

The Apple Silicon support for SQLitePCLRaw is currently only available in the 2.0.5 pre-release versions.


Related questions

5.0 RC1 logs query splitting warnings for queries using AutoMapper ProjectTo hot 40
A host error has occurred during startup operation (5.0.0-preview.4.20220.10 and 5.0.0-preview.5.20278.2) hot 35
[.Net Framework 4.8]Library e_sqlite3 not found hot 31
EF Migration Error : Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions hot 31
Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version= - efcore hot 29
"Enumerator failed to MoveNextAsync" when using SingleOrDefaultAsync - after Save hot 16
EF core 3 query LastOrDefault on entity with OwnsOne cannot translate expression hot 14
MissingMethodException: Method not found: 'Boolean Microsoft.EntityFrameworkCore.Migrations.IMigrationsModelDiffer.HasDifferences - efcore hot 12
Can't build for netcoreapp3.1 - Could not load file or assembly 'Microsoft.CodeAnalysis, Version=' hot 12
The SqlParameterCollection only accepts non-null SqlParameter type objects, not SqlParameter objects hot 11
What's the recommended way to .Join() using Keyless types in EF5? hot 10
[BUG] A second operation started on this context before a previous operation completed. This is usually caused by different threads using the same instance of DbContext. hot 10
Unable to create migrations without Microsoft.EntityFrameworkCore.Design in ASP.NET Core Web layer. hot 10
Cannot create a DbSet for 'Model' because this type is not included in the model for the context. hot 9
DbSet<T>.OfType<TDerived>() does not work hot 9
Github User Rank List