簡體   English   中英

與EF 6一起使用時無法加載文件或程序集'System.Data.SQLite'

[英]Could not load file or assembly 'System.Data.SQLite' when using with EF 6

我使用VS 2013和.Net 4.5框架創建了一個簡單的控制台應用程序。 我試圖實現一個使用Entity Framework&SQLite的非常簡單的目標,我希望使用代碼優先方法從我的模型中創建一個表。 我已經安裝了NuGet軟件包 ,以便能夠在我的項目中使用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; }
}

因此,在這里我只是嘗試向DbContext的AppConfig DbSet添加一個新的ApplicationConfiguration obj。

但是,在執行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.

我在Visual Studio 2013 Update 4上使用EF 6.1.3,SQLite 1.0.96.0和SQLite.CodeFirst 0.9.5.0,沒有出現此類問題。 嘗試更新。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM