EntityFramwork尝试加载旧/非现有的程序集版本

时间:2018-04-10 15:03:21

标签: c# entity-framework

因为星期天我有以下例外:

  

System.IO.FileLoadException:'无法加载文件或程序集   '基础设施,版本= 1.0.6561.42339,文化=中立,   PublicKeyToken = 9beef0ff5a4acdf8'或其依赖项之一。该   找到程序集的清单定义与程序集不匹配   参考。 (HRESULT异常:0x80131040)'

Fusion Log:

*** Assembly Binder Log Entry  (10.04.2018 @ 15:56:06) ***

The operation failed.
Bind result: hr = 0x80131040. No description available.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\projectsTFS\MyApp\Source\MyApp\MyApp\bin\x64\Debug\MyApp.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Infrastructure, Version=1.0.6561.42339, Culture=neutral, PublicKeyToken=9beef0ff5a4acdf8
 (Fully-specified)
LOG: Appbase = file:///C:/projectsTFS/MyApp/Source/MyApp/MyApp/bin/x64/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyApp.exe
Calling assembly : EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\projectsTFS\MyApp\Source\MyApp\MyApp\bin\x64\Debug\MyApp.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Infrastructure, Version=1.0.6561.42339, Culture=neutral, PublicKeyToken=9beef0ff5a4acdf8
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/projectsTFS/MyApp/Source/MyApp/MyApp/bin/x64/Debug/Infrastructure.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\projectsTFS\MyApp\Source\MyApp\MyApp\bin\x64\Debug\Infrastructure.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Infrastructure, Version=1.0.6674.28044, Culture=neutral, PublicKeyToken=9beef0ff5a4acdf8
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

当我想通过实体框架(6.2)

访问数据库时出现

第一次使用数据库是代码首次迁移:

//Migrator checking the current UpdateState and log the currently pending migrations
DbMigrator mig = new DbMigrator(new Configuration());
foreach (var migration in mig.GetPendingMigrations())
{
    _logger.Log("Open Migration: " + migration, Category.Debug, Priority.None);
}

_logger.Log("Start Migrations", Category.Debug, Priority.None);

//Initialize the Database and Update it
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DatabaseContext, Configuration>());
// To run Seed method
mig.Update(); // X <-- ERROR

当我跳过代码第一次迁移时,错误发生在数据库的第一个选择上。

这发生在'DatabaseModule'中,主应用程序使用prism mef加载。所有(33)项目都引用了基础设施项目(直接而不是dll)。

我所看到的:

版本6561来自~2017.12.18,也是(偶然?)上次迁移的日期。版本6674是从今天2018.04.10开始的最新版本。其他(Sub)命名空间,如Infrastructure.XmlSerializers或Infrastructure.resources,从实际版本中使用,显示在程序集绑定日志查看器(fuslogvw.exe)中。

当我从没有Visual Studio的Debug文件夹启动direclty时,应用程序启动时没有错误。

环境:

  • Visual Studio 2017 - 15.6.5(最新)
  • .NET 4.6 - 4.7.1(尝试更改此内容但没有成功)
  • x64申请
  • 签名申请(也可以不签名试用)
  • 解决方案中的33个项目
  • 没有开放/待定迁移

到目前为止我尝试了什么:

  • 清除所有bin文件夹
  • 清除临时文件夹/缓存(C:\ Users \%USERNAME%\ AppData \ Local \ Temp,C:\ Windows \ Temp)
  • 未在GAC注册
  • 清洁解决方案,重建解决方案很多次
  • 初始化了一个完整的新数据库
  • 在整个解决方案中搜索“6561”

我的想法已经不多了。有人可以帮忙吗?

期待新的想法, 马可

1 个答案:

答案 0 :(得分:0)

&#34;溶液&#34;

经过更长时间的调查并深入了解项目的清单/参考资料后,我使用AsmSpy来获取更复杂的依赖项列表。

asmspy c:\projectsTFS\MyApp\Source\MyApp\MyApp\bin\x64\Debug\ -a -s -b -i

并得到一些错误。但大多数错误来自系统引用,如:

System Dependencies

其他人看起来更具有针对性,因为它们被基础设施引用:

SignalR

此后我更新了大部分NuGe​​t包。

之后,错误仍然存​​在,但我可以跳过它们,解决方案正常开始!

至少我检查&#34;选项&gt;调试&gt;一般&gt;启用Just My Code&#34;而且我再也看不到错误了。