I’m encountering an issue with assembly version mismatch when using Microsoft.Data.Sqlite.SqliteConnection in a .NET Framework 4.6.1 project. Here’s the error message
public DbSet<Setting> Setting { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (DatabasePassword.Length != 0)
{
optionsBuilder.UseSqlite($"Data Source={DatabasePath};Password={DatabasePassword};pooling=false");
}
else
{
optionsBuilder.UseSqlite($"Data Source={DatabasePath};pooling=false");
}
}
// Retrieve all settings
var settings = data.Setting.ToList();
I’m getting:
System.TypeInitializationException: ‘The type initializer for ‘Microsoft.Data.Sqlite.SqliteConnection’ threw an exception.’
FileLoadException: Could not load file or assembly ‘SQLitePCLRaw.provider.dynamic_cdecl, Version=2.1.6.2060, Culture=neutral, PublicKeyToken=b68184102cba0b3b’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Details:
.NET Framework version: 4.6.1
Microsoft.Data.Sqlite.SqliteConnection version causing the issue: 3.1
Working fine with .NET 6 and Microsoft.Data.Sqlite.SqliteConnection version 8.0
I’ve tried updating packages, checking dependencies, and adding assembly binding redirects without success.
How can I resolve this assembly mismatch error and use Microsoft.Data.Sqlite.SqliteConnection version 3.1 with .NET Framework 4.6.1?
Any help or insights on how to resolve this issue would be greatly appreciated. Thank you!