Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting Could not load file or assembly error on a System.Configuration DLL when using framework 4.0?

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!

like image 407
topwik Avatar asked Jul 21 '10 15:07

topwik


2 Answers

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.

like image 50
topwik Avatar answered Oct 05 '22 22:10

topwik


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.

like image 37
Maslow Avatar answered Oct 05 '22 22:10

Maslow