使用框架 4.0 时,为什么我会收到无法在 System.Configuration DLL 上加载文件或程序集错误?

发布于 2024-09-10 23:36:53 字数 1393 浏览 4 评论 0原文

在我们升级到 Visual Studio 2010 和 4.0 框架后,我们的主干构建立即开始出现无法加载文件或程序集错误。

我们确定 3.5 项目无法引用 4.0 项目,否则我们会收到此错误,因为如错误所述,此程序集是由比当前加载的运行时更新的运行时构建的,无法加载

我们已经解决了这个问题,并且主干一直构建得很好。

然而,我最近做了一个分支和标记,当我尝试构建分支时,突然这个错误再次出现;但该错误与我们自己的 .net 4.0 项目之一对 System.Configuration DLL 的引用有关。

Core.Dev\Towps\Projetcs\Application\MyService 中的 Towps.Namespace.MyService.csproj:
RG0000:无法加载引用的程序集

“C:\ Windows \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Configuration \ v4.0_4.0.0.0__b03f5f7f11d50a3a \ System.Configuration.dll”。
捕获BadImageFormatException,说“无法加载文件或程序集
'C:\Windows\Microsoft.Net\ assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' 或其依赖项之一
此程序集由更新的运行时构建。当前加载的运行时,无法加载。”。在 ResGen(0, 0) 中

我尝试将该系统上的特定版本属性设置为 true。配置 DLL 引用为 true。
我可以在其属性中看到运行时版本为 v4.0.30319,版本为 4.0.0.0。
DLL引用的路径是C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll,对我来说看起来不错。

CrusieControl 使用 MSBuild 尝试构建的 csproj 文件的目标框架是针对框架 4.0。再次看起来不错。

它内置于 IDE 中,适用于 trunk 和 .分支。巡航控制系统将其安装在后备箱中。当 CrusieControl 尝试构建时,分支构建失败。

有什么想法可能会发生什么吗?

这可能是 MSBuild 不匹配,但我扫描了 CruiseControl 正在使用的配置文件和 msbuild proj 文件,并且没有对旧 MSBuild 的引用;这是有道理的,因为所有这些都已更新以使主干正常工作。

分支只是主干的复制品,所以我很难确定可能有什么区别!

Immediately after we upgraded to visual studio 2010 and the 4.0 framework our trunk build started breaking with the Could not load file or assembly error.

We determined that a 3.5 project couldn't reference a 4.0 project else we'd get this error because, as the error states, This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

We've since resolved this and the trunk has been building fine.

I recently did a branch and tag, however, and suddenly this error has resurfaced when I try to build the branch; except the error is regarding one of our own .net 4.0 project's reference to System.Configuration DLL.

Towps.Namespace.MyService.csproj in Core.Dev\Towps\Projetcs\Application\MyService:
RG0000: Could not load referenced assembly

"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll".
Caught a BadImageFormatException saying "Could not load file or assembly
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' or one of its dependencies.
This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.". in ResGen(0, 0)

I tried setting the specific version property on that system.Configuration DLL ref to true.
I can see in it's properties that the runtime version is v4.0.30319 and the Version is 4.0.0.0.
The path to the DLL ref is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll which to me looks fine.

The target framework for the csproj file that CrusieControl is using MSBuild to try to build is targeting framework 4.0. Again seems fine.

It builds in the IDE for both trunk & branch. Cruise Control build it in the trunk. The branch build fails when CrusieControl tries to build.

Any ideas what could be happening?

It could be an MSBuild mismatch but I've scanned the config files and msbuild proj files that CruiseControl is using and there are no references to older MSBuilds; which makes sense since all those were updated to get the trunk working.

The branch was simply a copy of the trunk so I'm having difficulty determining what could be the difference!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

勿挽旧人 2024-09-17 23:36:53

事实证明,在我分支后,cc.net 使用的分支构建目录中的所有 .proj 文件都恢复为使用 ToolVerison="3.5"。
我以为我已将所有 ToolsVersion="4.0" 项目和配置更改提交到我创建分支的主干;显然不是。

It turns out that after I branched, all the .proj files in my branch build directory that cc.net uses were back to using ToolVerison="3.5".
I thought I committed all the ToolsVersion="4.0" proj and config changes to the trunk from which I made the branch; evidentially not.

国际总奸 2024-09-17 23:36:53

差异很可能是提示路径不再在新分支上排列。但是您的描述中没有日志可以继续。您传递的命令行选项是什么?在 ccnet.config 以及任何其他可能进入的内容(如果 ccnet.config 指向调用 msbuild 而不是直接指向 .sln< 的构建脚本) /code> 或 .csproj 文件。

在两者上打开 msbuild 的 /v:d,然后比较该程序集或涉及/靠近它的其他程序集的参考分辨率(或构建顺序等)。

另外,您是否提供了两者上的 msbuild 路径?

msbuild4="C:\WINNT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

<msbuild>
    <executable>$(msbuild4)</executable>

在您的 ccnet.config 中?

我已经看到它在 msbuild4 /tv:3.5 期间报告了 2.0 构建可执行文件:

<Message Text="MSBuildToolsPath:$(MSBuildToolsPath)" />
<Message Text="MSBuildToolsVersion:$(MSBuildToolsVersion)" />

MSBuildToolsPath:C:\WINNT\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion:2.0

所以这似乎不是很有用。

我想查看分支和主干的配置块。

我知道构建脚本中有一些路径在我的分支中失败,因为有一个硬编码路径对分支无效。我必须调整 ccnet.config 来传递这些项目的参数以覆盖分支。

The difference could easily be hint paths no longer lining up on the new branch. However there's not a log to go on in your description. What are the command line options you are passing? In ccnet.config and also any others that may get in if ccnet.config is pointing at a build script that calls msbuild instead of directly to a .sln or .csproj file.

Turn on /v:d for the msbuild on BOTH and then compare the reference resolutions (or build order, etc..) for that assembly or other ones involved/near it.

Also are you providing the path to msbuild on both?

msbuild4="C:\WINNT\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"

<msbuild>
    <executable>$(msbuild4)</executable>

in your ccnet.config?

I've seen it report the 2.0 build executable during a msbuild4 /tv:3.5:

<Message Text="MSBuildToolsPath:$(MSBuildToolsPath)" />
<Message Text="MSBuildToolsVersion:$(MSBuildToolsVersion)" />

MSBuildToolsPath:C:\WINNT\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion:2.0

so that didn't seem very useful.

I'd like to see the config blocks for both branch and trunk.

I know I had some paths in the buildscript that failed in my branch because there was a hardcoded path that would not be valid for the branch. I had to adjust the ccnet.config to pass in arguments for those items to override for the branch.

逆夏时光 2024-09-17 23:36:53

请检查您的客户端支持的.net框架版本。例如sharepoint2010将不支持4.0或更高版本.net框架构建的dll。它将仅支持 3.5 或更低版本。

Please check .net framework version supported by your client. For example sharepoint2010 will not support dll built by 4.0 or higher .net framework. It will support only 3.5 or below.

笑饮青盏花 2024-09-17 23:36:53

我知道有点晚了,但如果其他人有这个问题,请尝试将 RuntimeVersion 添加到您的 .dna 文件中(如果它尚不存在)。

<DnaLibrary Name="PROJECTNAME" RuntimeVersion="v4.0">

A bit late I know, but if anybody else has this issue, try adding the RuntimeVersion into your .dna file if it does not already exist.

<DnaLibrary Name="PROJECTNAME" RuntimeVersion="v4.0">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文