question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add EF Core Sqlite Provider exception

See original GitHub issue

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();
    });
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
CallMeOzzcommented, Apr 2, 2020

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!

1reaction
kkbrucecommented, Apr 4, 2020

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQLite EF Core Database Provider Limitations
If you attempt to apply one of the unsupported operations to a SQLite database then a NotSupportedException will be thrown. A rebuild will...
Read more >
asp.net core - Sqlite and SqlServer providers exception types
I use for two providers for Entity Framework Core in my ASP.NET Core application. SqlServer for production mode and Sqlite for integration tests ......
Read more >
EF Core with SQLite: worth the effort? : r/dotnet
The problem here is that it appears that trying to execute PRAGMA statements in EF core with Sqlite is... troublesome at best. From...
Read more >
Connect to SQLite Database with Entity Framework Core
Run the following command from the project root folder to install the EF Core database provider for SQLite from NuGet:
Read more >
Add SQLite DB to ASP.NET Core using EF Core code-first
In this post we will learn how to add a SQLite database to an ASP.NET core project using Entity Framework core, code-first.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found