lecaillon / Evolve

Database migration tool for .NET and .NET Core projects. Inspired by Flyway.
https://evolve-db.netlify.com
MIT License
849 stars 110 forks source link

Unable to load shared library 'SQLite.Interop.dll' #298

Open jake-carpenter opened 1 year ago

jake-carpenter commented 1 year ago

Getting this error even on minimal tests. Is there something I'm missing for running with a M1 Mac?

What I'm doing

create table dbo.Foo (
  Id int primary key identity(1,1),
  Bar varchar(100) null
)

What's happening

$ evolve migrate sqlserver -c "Data Source=localhost,5865;Database=master;User Id=sa;Password=Password12#;" -l ./
Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.TypeInitializationException: The type initializer for 'EvolveDb.Cli.Program' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'SQLite.Interop.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libSQLite.Interop.dll, 0x0001): tried: 'libSQLite.Interop.dll' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibSQLite.Interop.dll' (no such file), '/usr/lib/libSQLite.Interop.dll' (no such file, not in dyld cache), 'libSQLite.Interop.dll' (no such file), '/usr/local/lib/libSQLite.Interop.dll' (no such file), '/usr/lib/libSQLite.Interop.dll' (no such file, not in dyld cache)
   at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op)
   at System.Data.SQLite.SQLite3.StaticIsInitialized()
   at System.Data.SQLite.SQLiteLog.PrivateInitialize(String className)
   at System.Data.SQLite.SQLiteLog.Initialize(String className)
   at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
   at System.Data.SQLite.SQLiteConnection..ctor(String connectionString)
   at EvolveDb.Cli.Program..cctor() in C:\projects\evolve\src\Evolve.Cli\Program.cs:line 14
   --- End of inner exception stack trace ---
   at EvolveDb.Cli.Program..ctor() in C:\projects\evolve\src\Evolve.Cli\Program.cs:line 50
   at System.RuntimeType.CreateInstanceOfT()
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceOfT()
   at System.Activator.CreateInstance[T]()
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication`1.DefaultModelFactory()
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication`1.CreateModel()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication`1.get_Model()
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication`1.McMaster.Extensions.CommandLineUtils.Abstractions.IModelAccessor.GetModel()
   at McMaster.Extensions.CommandLineUtils.Conventions.OptionAttributeConventionBase`1.<>c__DisplayClass0_0.<AddOption>b__1(ParseResult _)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.HandleParseResult(ParseResult parseResult)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Parse(String[] args)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](String[] args)
   at EvolveDb.Cli.Program.Main(String[] args) in C:\projects\evolve\src\Evolve.Cli\Program.cs:line 16
[1]    2715 abort      evolve migrate sqlserver -c  -l ./

Additional info

I am on an arm64 M1 Macbook Pro with both .net 6.0 and 7.0 sdks

$ dotnet --list-sdks
6.0.405 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]

Attempted this with both 3.1.0 and 3.2.0-alpha1.

This minimal repro is tested working on both Windows 10 and an Intel Mac.

jake-carpenter commented 1 year ago

It looks like this is a symptom of System.Data.SqlClient and arm64 which can be solved by using Microsoft.Data.SqlClient.

I've read the other threads where this was an issue, but I'm wondering if PR #291 addresses some of those issues?

lecaillon commented 1 year ago

Hi, it is probably because there is no OSX distibution of Evolve.

lecaillon commented 1 year ago

Oh sorry, you are using the .NET tool. So normally it should be ok. The issue seems to be linked to the SQLite driver. Not the SQL Server one btw

lecaillon commented 1 year ago

The SQLite driver used by Evolve is only compatible with x86 and x64 platform: https://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki

lecaillon commented 1 year ago

If you'd use the Evolve lib in your project it should work well btw, because no database driver is included in it