raisedapp / Hangfire.Storage.SQLite

An Alternative SQLite Storage for Hangfire
https://www.nuget.org/packages/Hangfire.Storage.SQLite
MIT License
155 stars 31 forks source link

Add EF Core Sqlite Provider exception #24

Closed kkbruce closed 4 years ago

kkbruce commented 4 years ago

I add another SQLite provider, like EF Core SQLite to project will throw exception from run project .UseSQLiteStorage().

Exception thrown: 'System.MissingMethodException' in SQLite-net.dll
An exception of type 'System.MissingMethodException' occurred in SQLite-net.dll but was not handled in user code
Method not found: 'System.String SQLitePCL.raw.sqlite3_column_name(SQLitePCL.sqlite3_stmt, Int32)'.

In ASP.NET Core 3.1 API PoC project,

.csproj

<ItemGroup>
  <PackageReference Include="Hangfire.Core" Version="1.7.*" />
  <PackageReference Include="Hangfire.AspNetCore" Version="1.7.*" />
  <PackageReference Include="Hangfire.Storage.SQLite" Version="0.2.4" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
</ItemGroup>

startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddHangfire(configuration => configuration
        .UseSimpleAssemblyNameTypeSerializer()
        .UseRecommendedSerializerSettings()
        .UseSQLiteStorage());
    services.AddHangfireServer();
    services.AddControllers();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseRouting();
    app.UseAuthorization();

    app.UseHangfireDashboard();
    BackgroundJob.Enqueue(() => Console.WriteLine("Hello backgroundjobs."));
    RecurringJob.AddOrUpdate("Hello", () => Console.WriteLine("Hello, recurringJob."), Cron.Minutely);

   app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=Home}/{action=Index}/{id?}");
        endpoints.MapControllers();
    });
}
felixclase commented 4 years ago

I will be checking

jons-aura commented 4 years ago

I just ran into this as well. On a different note (and I can make it a separate issue if preferred) I'm trying to use this for integration testing and it would be helpful if it could take an existing DbConnection object as an overload.

CallMeOzz commented 4 years ago

This is due to HangFire.Storage.SQLite's underlying dependency on the sqlite-net-pcl package, which was built using an older version of SQLitePCL.raw (v1.1 or newer).

SQLitePCL.raw introduced breaking changes in the 2.0 version. (see: Changes in SQLitePCLRaw 2.0)

Microsoft.EntityFrameworkCore.Sqlite (>= 3.0) has a dependency on SQLitePCL.raw v2.0 (or newer)

This version incompatibility between SQLitePCL.raw v1.x and v2.x is causing the issue (see: /sqlite-net/issues/920)

I encountered this same issue recently... As usual, it took 10 times longer to identify the problem than to resolve it.

@kkbruce Since you are using EF Core 3.0, the resolution should be simple. For now, just add the sqlite-net-pcl Nuget package to your project, but specify the "1.7.302-beta" prerelease version of the package. This beta version of sqlite-net-pcl depends on SQLitePCLRaw.bundle_green (>= 2.0.1), and should override the older version of sqlite-net-pcl that is defined by HangFire.Storage.SQLite

@felixclase, While Microsoft.EntityFrameworkCore.Sqlite 3.0+ depends on SQLitePCLRaw v2.0+, Microsoft.EntityFrameworkCore.Sqlite 2.x still depends on SQLitePCLRaw v1.1.12, and is not compatible with v2.0. I'm guessing that EF Core 3.0 support would require a ".NETStandard,Version=2.1" dependency that references "sqlite-net-pcl (>= 1.7.302-beta)", while EF Core 2.2 support would require a ".NETStandard,Version=2.0" dependency that references "sqlite-net-pcl (>= 1.6.292)"

Hope this info helps!

kkbruce commented 4 years ago

@CallMeOzz

  <ItemGroup>
    <PackageReference Include="HangFire.Core" Version="1.7.10" />
    <PackageReference Include="Hangfire.AspNetCore" Version="1.7.10" />
    <PackageReference Include="Hangfire.Storage.SQLite" Version="0.2.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
    <PackageReference Include="sqlite-net-pcl" Version="1.7.302-beta" />
  </ItemGroup>

It's work. thank you.

neckaros commented 4 years ago

I still get the error despite the fact that sqlite-net-pcl 1.7.335 is out and depends of SQLitePCLRaw.bundle_green (>= 2.0.3) but i still get the error.

I'm very new to dotnet but i think we should do a PR to update: https://github.com/raisedapp/Hangfire.Storage.SQLite/blob/e940762efa360274aea6b2e517ed76767e2e3976/src/main/Hangfire.Storage.SQLite/Hangfire.Storage.SQLite.csproj#L37

if so i can do a PR