Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite - Design time unable to load e_sqlite3.dll #10596

Closed
ErikEJ opened this issue Dec 20, 2017 · 9 comments
Closed

SQLite - Design time unable to load e_sqlite3.dll #10596

ErikEJ opened this issue Dec 20, 2017 · 9 comments

Comments

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 20, 2017

When calling the design time service from a VS extension, it is unable to load the sqlite.dll. The file is present in the x86 folder below the sqlite provider and design time dll files. Copying the x86 file one level up does not work.

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 DLL 'e_sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   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, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   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.Scaffolding.Internal.SqliteDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\sqlcetoolbox\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 111

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 DLL 'e_sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   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, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   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.Scaffolding.Internal.SqliteDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, Boolean useDatabaseNames)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ModelScaffolder.Generate(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas, String projectPath, String outputPath, String rootNamespace, String contextName, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
   at ReverseEngineer20.EfCoreReverseEngineer.GenerateFiles(ReverseEngineerOptions reverseEngineerOptions)
   at EFCorePowerTools.Handlers.ReverseEngineerHandler.<ReverseEngineerCodeFirst>d__2.MoveNext() in C:\projects\sqlcetoolbox\src\GUI\EFCorePowerTools\Handlers\ReverseEngineerHandler.cs:line 111

Pakcages.config:


<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFrameworkCore.SqlServerCompact40" version="2.0.1.1" targetFramework="net461" />
  <package id="Microsoft.CSharp" version="4.4.0" targetFramework="net461" />
  <package id="Microsoft.Data.Sqlite.Core" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Design" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Relational" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Sqlite" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Sqlite.Core" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.SqlServer" version="2.0.1" targetFramework="net461" />
  <package id="Microsoft.Extensions.Caching.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Caching.Memory" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Options" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Primitives" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net461" />
  <package id="Remotion.Linq" version="2.1.1" targetFramework="net461" />
  <package id="SQLitePCLRaw.bundle_green" version="1.1.7" targetFramework="net461" />
  <package id="SQLitePCLRaw.core" version="1.1.7" targetFramework="net461" />
  <package id="SQLitePCLRaw.lib.e_sqlite3.linux" version="1.1.7" targetFramework="net461" />
  <package id="SQLitePCLRaw.lib.e_sqlite3.osx" version="1.1.7" targetFramework="net461" />
  <package id="SQLitePCLRaw.lib.e_sqlite3.v110_xp" version="1.1.7" targetFramework="net461" />
  <package id="SQLitePCLRaw.provider.e_sqlite3.net45" version="1.1.7" targetFramework="net461" />

Further technical details

EF Core version: 2.0.1
Database Provider: (e.g. Microsoft.EntityFrameworkCore.Sqlite)
Operating system: Win 10
IDE: (e.g. Visual Studio 2017 15.5.1)

@ErikEJ ErikEJ changed the title SQLite - Design time unable to load sqlte SQLite - Design time unable to load e_sqlite3.dll Dec 20, 2017
@bricelam
Copy link
Contributor

You'll need to do a lot of AppDomain magic to make this work in-proc with VS. The AppDomainOperationExecutor was going to serve as the basis of our VS integration.

@bricelam
Copy link
Contributor

Oh wait, you may just need to distribute e_sqlite3.dll as part of your extension.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 20, 2017

As you can see from my description, I already do that, but the managed code seems to be looking for it in the wrong place.

@bricelam
Copy link
Contributor

bricelam commented Dec 20, 2017

Looks like the search looks in:

  1. SQLitePCL.Settings.BaseDirectoryForDynamicLoadNativeLibrary (you can set this)
  2. AppDomain.CurrentDomain.BaseDirectory
  3. Directory of SQLitePCLRaw.provider.e_sqlite3.dll

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 21, 2017

Great, let me try "1"

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 24, 2017

No luck...

Looks like VS load a version of the sqlite driver of from

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\ManagedLanguages\VBCSharp\LanguageServices\SQLitePCLRaw.provider.e_sqlite3.dll

And calling SQLitePCL.Settings.BaseDirectoryForDynamicLoadNativeLibrary fails with "Typeload Exception" ??? ericsink/SQLitePCL.raw#188

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 24, 2017

Wondering if ths is a valid fix? aspnet/Microsoft.Data.Sqlite#249 (comment)

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 26, 2017

Fixed! Base issue was that VS and some extension were using and loading various old versions of SQLite.PCL.raw

My fix - wonder if there are some product changes that would make this easier?

1: Used a SQLite ADO.NET provider that includes the x86 sqlite3.dll as a resource (so no looking in the file system) iso Microsoft.Data.Sqlite

2: Implemented my "own" SqliteDatabaseModelFactory that uses the implementation above (which is System.Data.Sqlite.dll) - if I could do scaffolding with a IDbConnection, iso a connection string, I could maybe have avoided this extra code?

ErikEJ/SqlCeToolbox@e02c6a1

https://github.com/aspnet/EntityFrameworkCore/blob/dev/src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs#L84

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 28, 2017

@ErikEJ ErikEJ closed this as completed Dec 28, 2017
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants