部分迁移到.NET 4 - 无法找到程序集

时间:2012-07-19 14:38:44

标签: c# .net .net-4.0 .net-2.0

我有一个C#应用程序,包含一个引用很多dll的exe,都是用.NET构建的。我想集成一个用.NET 4构建的dll,所以要做到这一点,我首先需要重建exe。 NET 4并确保一切都像以前一样。

所以我用.NET 4(完整的配置文件)重建了exe,用它替换了旧的exe,然后重新启动了应用程序。我收到以下错误:

"Failure loading the types from the assembly 'blorg.dll'"(其中'blorg'是程序集真实名称的网络安全别名,它是exe引用的旧.NET 2程序集之一。)

内部例外是:

"Could not load file or assembly file 'file:///C:\\(...)blorg or one of its depedencies. The system cannot find the file specified.":"file:///C:\\(...)blorg"

FusionLog说:

=== Pre-bind state information ===
LOG: User = NT AUTHORITY/SYSTEM
LOG: Where-ref bind. Location= C:\(...)\blorg
LOG: Appbase = file:///C:/(...)/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\(...)\blorg.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: Attempting download of new URL file:///C:/(...)/blorg

有问题的dll就在与exe相同的文件夹中。当我在VS2005 for .NET 2中构建exe时,整个工作正常。唯一的变化是我打开将可执行文件的解决方案(可执行文件有自己的解决方案)转换为VS2010,将目标更改为.NET 4 ,重建它并将其复制粘贴到文件夹。哦,这是在调试,而其余的是在发布。我在网上搜索了一段时间,但我找不到任何可以帮助我诊断问题的东西。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

事实证明,其中一些程序集或它们的依赖项是混合模式.NET 2.0,因此修复程序是在app.config中添加属性“useLegacyV2RuntimeActivationPolicy”到启动元素:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="4.0" sku=".NETFramework,Version=v4.0" />
</startup>