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]Error on database update command #3573

Closed
Codenator81 opened this issue Oct 27, 2015 · 11 comments
Closed

[sqlite]Error on database update command #3573

Codenator81 opened this issue Oct 27, 2015 · 11 comments

Comments

@Codenator81
Copy link

In project.json I point only dnxcore50

Dnx:
Version: 1.0.0-rc1-16031
Type: CoreClr
Architecture: x64
OS Name: Windows
OS Version: 10.0
Runtime Id: win10-x64

EF provider Sqlite

F:\Code\asp.net\myproject\Site>dnx ef database update
System.BadImageFormatException: An attempt was made to load a program with an in
correct format. (Exception from HRESULT: 0x8007000B)
   at System.Runtime.Loader.AssemblyLoadContext.InternalLoadUnmanagedDllFromPath
(String unmanagedDllPath)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.LoadUnmanagedLibrary(St
ring name)
   at Microsoft.Dnx.Host.LoaderContainer.LoadUnmanagedLibrary(String name)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadUnmanagedDll(String unmanaged
DllName)
   at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unman
agedDllName, IntPtr gchManagedAssemblyLoadContext)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(IntPtr filenam
e, Sqlite3Handle& ppDb, Int32 flags, IntPtr vfs)
   at Microsoft.Data.Sqlite.Interop.NativeMethods.sqlite3_open_v2(String filenam
e, Sqlite3Handle& ppDb, Int32 flags, String vfs)
   at Microsoft.Data.Sqlite.SqliteConnection.Open()
   at Microsoft.Data.Entity.Storage.RelationalConnection.Open()
   at Microsoft.Data.Entity.Storage.Internal.SqliteRelationalConnection.Open()
   at Microsoft.Data.Entity.Storage.Internal.RelationalCommand.Execute[T](IRelat
ionalConnection connection, Func`3 action, String executeMethod, Boolean openCon
nection, Boolean closeConnection)
   at Microsoft.Data.Entity.Storage.Internal.RelationalCommand.ExecuteScalar(IRe
lationalConnection connection, Boolean manageConnection)
   at Microsoft.Data.Entity.Migrations.HistoryRepository.Exists()
   at Microsoft.Data.Entity.Migrations.Internal.Migrator.Migrate(String targetMi
gration)
   at Microsoft.Data.Entity.Design.MigrationsOperations.UpdateDatabase(String ta
rgetMigration, String contextType)
   at Microsoft.Data.Entity.Commands.Program.Executor.Execute(Action action)
An attempt was made to load a program with an incorrect format. (Exception from
HRESULT: 0x8007000B)
@natemcmaster
Copy link
Contributor

This is a problem with https://github.com/aspnet/microsoft.data.sqlite. It appears the library is attempting to load the wrong bitness (x86 vs x64)

@divega
Copy link
Contributor

divega commented Oct 27, 2015

@natemcmaster I definitively see the DNX package loader in the exception above, so this could be an issue @moozzyk's code.

@divega
Copy link
Contributor

divega commented Oct 27, 2015

cc @muratg

@moozzyk
Copy link

moozzyk commented Oct 28, 2015

Might be related to the package layout. We create a lookup table where the lib name without the extension is the key and the path is the value. CoreClr calls us when they need to load a native lib and we resolve the path using the lookup above and have them load the lib from the path (this way we don't need to worry about loading native libs on different platforms).
If libs for both architectures are defined in the runtimes section then the last would win. The expectation is that the project.lock.json section for a specific architecture should not contain entries libs for a different architecture (at least in the runtimes section).

@Codenator81
Copy link
Author

https://gist.github.com/Codenator81/c6f3634a7d6bc79d0896 my project.lock.json file if it helps
Version: 1.0.0-rc1-16048
Type: CoreClr
Architecture: x64
OS Name: Windows
OS Version: 10.0
Runtime Id: win10-x64

@Codenator81
Copy link
Author

I find problem.
As mentioned @moozzyk I check project.lock.json file. There were wrong dependencies for sqlite.
When I on coreclr do dnu restore there in lock file dependecies point to dot.net library but not coreclr.
When I change for example:

 "EntityFramework.Sqlite/7.0.0-rc2-16153": {
        "type": "package",
        "dependencies": {
          "EntityFramework.Relational": "7.0.0-rc2-16153",
          "Microsoft.CSharp": "4.0.1-beta-23427",
          "Microsoft.Data.Sqlite": "1.0.0-rc2-15761",
          "System.IO.FileSystem": "4.0.1-beta-23427"
        },
        "compile": {
          "lib/dotnet5.4/EntityFramework.Sqlite.dll": {}
        },
        "runtime": {
          "lib/dotnet5.4/EntityFramework.Sqlite.dll": {}
        }
      },

to

 "compile": {
          "lib/netcore50/EntityFramework.Sqlite.dll": {}
        },
        "runtime": {
          "lib/netcore50/EntityFramework.Sqlite.dll": {}

everithing works good.

I change this in all lock file where sqlite mentioned)))
So solution is when do dnu restore need provide right runtime and compile packages

My dnx: dnx-coreclr-win-x64.1.0.0-rc2-16062
Sorry for my English as well. I try best

Update:
When change in two places native:

"Microsoft.Data.Sqlite/1.0.0-rc2-15761": {
        "type": "package",
        "dependencies": {
          "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc2-15748",
          "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16062",
          "System.Collections": "4.0.11-beta-23427",
          "System.ComponentModel": "4.0.1-beta-23427",
          "System.Data.Common": "4.0.1-beta-23427",
          "System.Diagnostics.Debug": "4.0.11-beta-23427",
          "System.Globalization": "4.0.11-beta-23427",
          "System.IO.FileSystem": "4.0.1-beta-23427",
          "System.Linq": "4.0.1-beta-23427",
          "System.Reflection": "4.1.0-beta-23427",
          "System.Resources.ResourceManager": "4.0.1-beta-23427",
          "System.Runtime": "4.0.21-beta-23427",
          "System.Runtime.Extensions": "4.0.11-beta-23427",
          "System.Runtime.Handles": "4.0.1-beta-23427",
          "System.Runtime.InteropServices": "4.0.21-beta-23427",
          "System.Text.Encoding": "4.0.11-beta-23427",
          "System.Threading.Tasks": "4.0.11-beta-23427"
        },
        "compile": {
          "lib/dotnet5.4/Microsoft.Data.Sqlite.dll": {}
        },
        "runtime": {
          "lib/dotnet5.4/Microsoft.Data.Sqlite.dll": {}
        },
        "native": {
          "runtimes/win/native/x64/sqlite3.dll": { },
          "runtimes/win/native/x64/x86/sqlite3.dll": {},
          "runtimes/win/native/x86/sqlite3.dll": {}
        }
      },

to

"native": {
          "runtimes/win/native/x64/sqlite3.dll": { }
        }

works as well.
May be problem becouse pointed multiple dll`s in native section?

@Codenator81
Copy link
Author

On linux:

fail: Microsoft.Data.Entity.Query.Internal.QueryCompiler[1]
      An exception occurred in the database while iterating the results of a query.
      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_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.Data.Entity.Storage.RelationalConnection.Open()
         at Microsoft.Data.Entity.Storage.Internal.SqliteRelationalConnection.Open()
         at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
         at Microsoft.Data.Entity.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
         at lambda_method(Closure , QueryContext )
         at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_1`1.<CompileQuery>b__1(QueryContext qc)
Application startup exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. ---> 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_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.Data.Entity.Storage.RelationalConnection.Open()
   at Microsoft.Data.Entity.Storage.Internal.SqliteRelationalConnection.Open()
   at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
   at Microsoft.Data.Entity.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
   at lambda_method(Closure , QueryContext )
   at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_1`1.<CompileQuery>b__1(QueryContext qc)
   at System.Linq.Queryable.Any[TSource](IQueryable`1 source)
   at WeebDoCMF.WDCore.Models.SeedData.<InitializeWeebDoCMFDatabaseAsync>d__0.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at WeebDoCMF.Startup.Configure(IApplicationBuilder app)
   at WeebDoCMF.Startup.ConfigureDevelopment(IApplicationBuilder app, ILoggerFactory loggerFactory)
   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.AspNet.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
   --- 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.AspNet.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
fail: Microsoft.AspNet.Hosting.Internal.HostingEngine[7]
      Application startup exception
      System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. ---> 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_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.Data.Entity.Storage.RelationalConnection.Open()
         at Microsoft.Data.Entity.Storage.Internal.SqliteRelationalConnection.Open()
         at Microsoft.Data.Entity.Query.Internal.QueryingEnumerable.Enumerator.MoveNext()
         at Microsoft.Data.Entity.Query.QueryMethodProvider.GetResult[TResult](IEnumerable`1 valueBuffers)
         at lambda_method(Closure , QueryContext )
         at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass18_1`1.<CompileQuery>b__1(QueryContext qc)
         at System.Linq.Queryable.Any[TSource](IQueryable`1 source)
         at WeebDoCMF.WDCore.Models.SeedData.<InitializeWeebDoCMFDatabaseAsync>d__0.MoveNext()
         --- End of inner exception stack trace ---
         at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
         at System.Threading.Tasks.Task.Wait()
         at WeebDoCMF.Startup.Configure(IApplicationBuilder app)
         at WeebDoCMF.Startup.ConfigureDevelopment(IApplicationBuilder app, ILoggerFactory loggerFactory)
         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.AspNet.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
         at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()
         --- 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.AspNet.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
         at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()

Looks like sqlite totally broken on coreclr? It works great before...
Current dnx:
Version: 1.0.0-rc2-16063
Type: CoreClr
Architecture: x64
OS Name: Linux
OS Version: ubuntu 14.04
Runtime Id: ubuntu.14.04-x64
Sorry for emotions ))

@natemcmaster
Copy link
Contributor

Possible duplicate of aspnet/Microsoft.Data.Sqlite#128. Sqlite stopped working recently on coreclr due to recent changes in DNX.

@natemcmaster
Copy link
Contributor

@Codenator81 swapping DLLs from the dotnet5.4 to netcore50 TFM works because this version does not have the native library loading code. See https://github.com/aspnet/Microsoft.Data.Sqlite/blob/1bd890502aa86b553caa91f32825394c97e956e6/src/Microsoft.Data.Sqlite/Utilities/NativeLibraryLoader.cs#L4

@rowanmiller
Copy link
Contributor

Looks like everything has been addressed (or tracked elsewhere). Feel free to open a new issue if you have other issues.

@Codenator81
Copy link
Author

Check on dnx 1.0.0-rc2-16128 coreclr x64. It fixed and Sqlite works without hacking in project.lock.json.

@Codenator81 Codenator81 changed the title Error on database update command [sqlite]Error on database update command Nov 9, 2015
@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

6 participants