【问题标题】:Could not load file or assembly 'System.Data.SQLite' when using with EF 6与 EF 6 一起使用时无法加载文件或程序集“System.Data.SQLite”
【发布时间】:2015-05-16 09:15:14
【问题描述】:

我使用 VS 2013 和 .Net 4.5 框架创建了一个简单的控制台应用程序。我正在尝试实现一个非常简单的使用实体框架和 SQLite 的目标,我希望使用代码优先的方法从我的模型中创建一个表。 我已经安装了NuGet package,以便能够在我的项目中使用 LINQ to SQLite。

以下是我的应用程序代码:

 static void Main(string[] args)
 {
     string _databaseFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TestSqliteDb.sdb");

     if (!File.Exists(_databaseFilePath))
         SQLiteConnection.CreateFile(_databaseFilePath);

     using (var testDb = new TestMovieDbContext())
     {
         testDb.AppConfigTable.Add(
             new ApplicationConfiguration
             {
                 ConfigKey = "CreatedDate",
                 ConfigValue = "12-03-2015"
             });
      }

public class TestMovieDbContext : DbContext
{
    public TestMovieDbContext()
        : base("name=TestDbConStr")
    {
    }

    public DbSet<ApplicationConfiguration> AppConfigTable { get; set; }
}

public class ApplicationConfiguration
{
    [Key]
    public string ConfigKey { get; set; }
    public string ConfigValue { get; set; }
}

所以,这里我只是尝试将一个新的 ApplicationConfiguration obj 添加到 DbContext 的 AppConfig DbSet 中。

但是,在执行 Add 方法行时,应用程序会抛出以下异常:

System.IO.FileLoadException was caught
  HResult=-2146234304
  Message=Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly`s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
  Source=mscorlib
  FileName=System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
  FusionLog==== Pre-bind state information ===
LOG: DisplayName = System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
 (Fully-specified)
LOG: Appbase = file:///E:/Projects/TestApplications/LinqToSqliteDemo/LinqToSqliteDemo/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
> LOG: This bind starts in default load context.
LOG: Using application configuration file: E:\Projects\TestApplications\LinqToSqliteDemo\LinqToSqliteDemo\bin\Debug\LinqToSqliteDemo.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
LOG: Attempting download of new URL file:///E:/Projects/TestApplications/LinqToSqliteDemo/LinqToSqliteDemo/bin/Debug/System.Data.SQLite.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

【问题讨论】:

标签: c# sqlite entity-framework-6 .net-assembly


【解决方案1】:

我在 Visual Studio 2013 Update 4 上使用 EF 6.1.3、SQLite 1.0.96.0 和 SQLite.CodeFirst 0.9.5.0 没有此类问题。尝试更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-13
    • 2011-03-24
    • 2013-11-07
    • 2011-12-11
    • 1970-01-01
    • 2016-08-16
    • 2014-07-04
    • 2019-01-30
    相关资源
    最近更新 更多