title: Why am I getting Could not load file or assembly error on a System.Configuration DLL when using framework 4.0?
body: <p>Immediately after we upgraded to visual studio 2010 and the 4.0 framework our trunk build started breaking with the <em>Could not load file or assembly error.</em><br><br>
  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, <em>This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded</em>. <br><br></p>
  
  <p>We've since resolved this and the trunk has been building fine.</p>
  
  <p>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.</p>
  
  <blockquote>
    <p>Towps.Namespace.MyService.csproj in Core.Dev\Towps\Projetcs\Application\MyService: <br>
    RG0000: Could not load referenced assembly <br><br>
    "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll".<br> Caught a BadImageFormatException saying "Could not load file or assembly <br> 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll' or one of its dependencies. <br>This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.". in ResGen(0, 0)</p>
  </blockquote>
  
  <p>I tried setting the specific version property on that system.Configuration DLL ref to true.<br> I can see in it's properties that the runtime version is v4.0.30319 and the Version is 4.0.0.0. <br>The path to the DLL ref is <em>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Configuration.dll</em> which to me looks fine.</p>
  
  <p>The target framework for the csproj file that CrusieControl is using MSBuild to try to build is targeting framework 4.0. Again seems fine.</p>
  
  <p>It builds in the IDE for both trunk &amp; branch. Cruise Control build it in the trunk. The branch build fails when CrusieControl tries to build.</p>
  
  <p>Any ideas what could be happening?</p>
  
  <p>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.</p>
  
  <p>The branch was simply a copy of the trunk so I'm having difficulty determining what could be the difference!</p>