使用EF 6时无法加载文件或程序集'System.Data.SQLite'
问题描述:
我使用VS 2013和.Net 4.5框架创建了一个简单的控制台应用程序。我试图实现一个非常简单的目标,即使用实体框架& SQLite,我希望使用代码优先方法从我的模型创建一个表。 我已经安装了NuGet package以便能够在我的项目中使用LINQ to SQLite。使用EF 6时无法加载文件或程序集'System.Data.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.
答
我使用EF 6.1.3,SQLite的1.0.96.0及SQLite.CodeFirst 0.9.5.0上Visual Studio 2013 Update 4没有这样的问题。尝试更新。
[位于程序集的清单定义与程序集引用不匹配]的可能重复(http://stackoverflow.com/questions/215026/the-located-assemblys-manifest-definition-does-not-match-the-汇编参考) – JNYRanger 2015-03-13 19:02:45
版本'1.0.66.0'似乎很古老,我不确定它将与.Net 4.5兼容([请参阅此处](http://stackoverflow.com/a/13496617/95573)) – SwDevMan81 2015-03-13 19:16:54