efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Unable to load DLL 'sqlite3' on windows.

Open PMExtra opened this issue 9 years ago • 10 comments

I want to Scaffold-DbContext with a sqlite database. I use the PMC (Package Manage Console) in the Visual Studio 2015. When I run the Scaffold-DbContext -Connection "FileName=sqlite.db" -Provider Microsoft.EntityFrameworkCore.Sqlite I get some error:

System.DllNotFoundException: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.Sqlite3_sqlite3.sqlite3_open_v2(IntPtr filename, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filename, Sqlite3Handle& ppDb, Int32 flags, String vfs)
   at Microsoft.Data.Sqlite.SqliteConnection.Open()
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteDatabaseModelFactory.Create(DbConnection connection, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteDatabaseModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.RelationalScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.SqliteScaffoldingModelFactory.Create(String connectionString, TableSelectionSet tableSelectionSet)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GetMetadataModel(ReverseEngineeringConfiguration configuration)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator.GenerateAsync(ReverseEngineeringConfiguration configuration, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContextAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<ScaffoldContextImpl>d__22.MoveNext()
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source, Int32& length)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass4_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Further technical details

EF Core version: 1.1.0 EF Core Tools version: 1.1.0-preview4-final Database Provider: Microsoft.EntityFrameworkCore.Sqlite Operating system: Microsoft Windows [Version 10.0.14393] x64 IDE: Visual Studio 2015

Full project.json

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.Sqlite": "1.1.0",
    "Microsoft.EntityFrameworkCore.Sqlite.Design": {
      "type": "build",
      "version": "1.1.0"
    },
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "NETStandard.Library": "1.6.1"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  }
}

PMExtra avatar Dec 21 '16 00:12 PMExtra

I tried create a new "Console Application (.NET Core)", and use the CLI to scaffold dbcontext, it's works great!

But I dont't know how to specify a project which be used to output, in the EFTools CLI. (output to another class library)

PMExtra avatar Dec 21 '16 00:12 PMExtra

This is a known limitation of .NET Standard Class Library projects. Using a Console App is the correct workaround.

bricelam avatar Dec 21 '16 01:12 bricelam

We've added a warning directing you down this path in an upcoming release.

bricelam avatar Dec 21 '16 01:12 bricelam

@bricelam If using a Console App is the correct workaround, is it also the case for a Unit Test project?

kevin-work avatar Jan 03 '17 09:01 kevin-work

I suspect so, yes. You might also be able to make your unit test project target .NET Core App instead of .NET Standard, but I'm not entirely sure if it will work. There have been some changes to how unit tests run that I need to catch up on.

bricelam avatar Jan 03 '17 16:01 bricelam

Closing as fixed since we have mitigated the issue.

divega avatar Jan 06 '17 19:01 divega

So, what is the solution?

alexsandro-xpt avatar Apr 02 '17 23:04 alexsandro-xpt

@alexsandro-xpt Can you submit a new issue describing your scenario? A lot has changed since this issue was created.

bricelam avatar Apr 03 '17 16:04 bricelam

What is the solution?

Mardoxx avatar Apr 26 '17 11:04 Mardoxx

@Mardoxx Can you submit a new issue describing your scenario? A lot has changed since this issue was created.

bricelam avatar Apr 26 '17 15:04 bricelam