SQLite.CodeFirst "The provider did not return a ProviderManifest instance."

c# ef-code-first entity-framework-6 sqlite system.data.sqlite

Question

I am trying to make work the simplest project using SQLite.CodeFirst (1.5.1.25, installed from NuGet package) along with the System.Data.SQLite (1.0.108, also NuGet).
However, adding a person will result in

The provider did not return a ProviderManifest instance.

exception. Sadly, there are no official example projects to draw inspiration from, so the following is aggregation of dozens of SO answers gets me following minimal example.
The context:

class Person
{
   [Key]
   public int ID { get; set; }
   public string Name { get; set; }
}

class MyDBContentext : DbContext
{
    public MyDBContentext(string connectionString) 
           : base(new SQLiteConnection() { ConnectionString = connectionString }, true)
    { }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyDBContentext>(modelBuilder);
        System.Data.Entity.Database.SetInitializer(sqliteConnectionInitializer);
    }

    public DbSet<Person> People { get; set; }
}

//main
var conStr = $"Data Source=eftest.sqlite;Version=3;Password=123;";
var ctx = new MyDBContentext(conStr);
ctx.People.Add(new Person() { Name = "foo" });//<--- exception throw here
var res = ctx.SaveChanges();

and the App.config:

  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)"
           invariant="System.Data.SQLite.EF6"
           description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
           type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite"
            description=".Net Framework Data Provider for SQLite"
            type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6"
          type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SqlClient"
          type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite"
          type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>
  </entityFramework>

There is also an inner exception (translated, since it ignores thread culture) if it is of any relevance:

The attempt of method System.Data.SQLite.EF6.SQLiteProviderManifest.GetProviderManifestToken(System.String) to access the method System.Data.SQLite.UnsafeNativeMethods.GetSettingValue(System.String, System.String) failed.

1
0
7/20/2018 9:02:17 AM

Accepted Answer

Reinstalling all NuGet packages (SQLite.CodeFirst, System.Data.SQLite and Entity framework) and cleaning the solution resolved the issue.

0
7/23/2018 8:44:00 AM

Popular Answer

For those who are having this issue in the future, delete all SQLite assemblies from your GAC. In my case, I had to run the followings from a command prompt with admin rights:

gacutil –u System.Data.SQLite
gacutil –u System.Data.SQLite.Linq


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow