gpt4 book ai didi

c# - 部分迁移到 .NET 4 - 找不到程序集

转载 作者:行者123 更新时间:2023-11-30 17:59:08 25 4
gpt4 key购买 nike

我有一个 C# 应用程序,由一个引用许多 dll 的 exe 组成,所有 dll 都是用 .NET 2 构建的。我想集成一个用 .NET 4 构建的 dll,所以要做到这一点,我首先需要在 . NET 4 并确保一切正常。

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

“从程序集 '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 ,重建它并将其复制粘贴到文件夹中。哦,它处于调试状态,而其余部分则处于发布状态。我在网上搜索了一段时间,但没有找到任何可以帮助我诊断问题的信息。有什么想法吗?

最佳答案

事实证明,其中一些程序集或其依赖项是混合模式 .NET 2.0,因此解决方法是进入 app.config 并将属性“useLegacyV2RuntimeActivationPolicy”添加到启动元素:

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

关于c# - 部分迁移到 .NET 4 - 找不到程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11563216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com