2012-07-19 29 views
3

我有一个C#应用程序,由一个引用很多dll的单个exe组成,所有这些都是用.NET 2构建的。我想集成一个使用.NET 4构建的dll,所以做到这一点我首先需要重新编译.NET 4中的exe文件,并确保一切正常。部分迁移到.NET 4 - 未能找到程序集

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

"Failure loading the types from the assembly 'blorg.dll'"(其中“blorg”是组装的真实姓名,这是旧的.NET组件2由exe文件引用的一个网安全的别名)。

内部异常是:

"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中为.NET 2构建exe文件时,整个工作正常。唯一发生的变化是我打开了将可执行文件(可执行文件具有自己的解决方案)的解决方案转换为VS2010,将目标更改为.NET 4 ,重建它并将其复制到文件夹。哦,它在调试中,其余的在发布。我在网上搜索了一段时间,但我没有找到任何可以帮助我诊断问题的东西。有什么想法吗?

+0

您是否启用允许.NET 4.0应用程序加载.NET 2.0程序集的标志?关于如何在此网站上提供几十个答案。大多数都在相关列表中。 – 2012-07-19 14:41:57

+0

什么标志? ---- – Asik 2012-07-19 14:47:52

+0

你看我没有找到它。 – 2012-07-19 16:02:54

回答

1

事实证明,一些这些组件或它们的依赖关系进行混合模式.NET 2.0,所以该修补程序是去在App.config和添加属性“useLegacyV2RuntimeActivationPolicy”到启动元件:

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