다음을 통해 공유


BadImageFormatException - This assembly is built by a runtime newer than the currently loaded

Strange thing happened today. I upgraded one of the internal tool to .Net 4.0 without any issues but as soon as I attempt to debug/run the binary, I’ll see this exception:

System.BadImageFormatException was unhandled
Message: Could not load file or assembly SomeTool.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Normally you see this exception if the machine doesn’t have right run time installed. But this was obviously not the case. Changing build to x86 or x64 didn’t made any difference either. Next I ran peverify.exe which happily reported that there was nothing wrong with the binary image. Finally I needed to pull out the big guns, ask fuslogvw, which would show me if there are any dependent assembly binding that was failing. But that also didn’t produce any boom sounds.

So the last resort was to just meditate over the issue for few minutes. And that works. In a sign of enlightenment I saw app.config buried along with bunch of files and it had these lines:

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v2.0.50727"/></startup></configuration>

Aha! Apparently the app.config doesn’t get updated (may be because it was in TFS?) when VS did the 4.0 upgrade. As app.config didn’t had anything else, just deleting this file solved the issue. I do wonder how many people come across this gotcha.

Comments

  • Anonymous
    May 14, 2013
    Solved a similar issue for me! Thanks!

  • Anonymous
    June 16, 2013
    thanks

  • Anonymous
    November 19, 2013
    I experienced 100% exactly the same issue, going from 2.0 to 4.0.  I would never have thought to look in the app.config files, but sure enough about a quarter of them had v4.0 while the rest had v2.0.50727.  And coincidentally all of the v2.0.50727 are empty (not in use for holding any settings).

  • Anonymous
    November 19, 2013
    Great, Thx!   I love google.

  • Anonymous
    November 19, 2013
    thanks a ton.. u saved my day :)

  • Anonymous
    January 19, 2014
    The comment has been removed

  • Anonymous
    February 06, 2014
    Thank you, we had the same issue and were wondering why... We had both versions in our app.config files.

  • Anonymous
    March 05, 2014
    Thank you. This solved my problem.

  • Anonymous
    March 17, 2014
    Saved my bacon today, thank you.

  • Anonymous
    April 15, 2014
    Thank you for this post! It could have taken ages before I checked app.config, had I not read this.

  • Anonymous
    May 02, 2014
    Thank you very much. This solved my issue! Big star for you for publishing this!

  • Anonymous
    August 07, 2014
    I'm not a developer but an integrator. I'm trying to connect from Citrix Provisioning Services MMC console to SCVMM version 2012 R2. I got the exact same error message as you did but I'm afraid, I could not find any resolution. Citrix requires that I install the SCVMM 2012 R2 console before I try to interface with SCVMM 2012 R2. I have installed it as well as ran a full Microsoft recommended updates. It appears the API for the version I'm connecting from will not interface with SCVMM 2012 R2. What I am confused about is, the Citrix software is offloading the API communication entirely to the SCVMM console installed locally on the server so the error is likely being presented by SCVMM. I figured I'd ask since it's identical to your error message but I don't particularly know how this can be corrected. Thanks, Rashid

  • Anonymous
    August 07, 2014
    If someone came to this threat due to an interface issue between Citrix Provisioning Services and SCVMM 2012 R2, then use this resolution: [...]Create a file “powershell.exe.config” in the ‘C:WindowsSystem32WindowsPowerShellv1.0′ and C:WindowsSysWOW64WindowsPowerShellv1.0 with the below contents and restart the server. <?xml version="1.0"?> <configuration> <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0.30319"/> <supportedRuntime version="v2.0.50727"/> </startup> </configuration> I wish I came up with the resolution but the I came across it from the website under REFERENCE. REFERENCE: merlus.com/.../integrating-pvs-on-windows-2008r2-with-scvmm2012

  • Anonymous
    October 29, 2014
    thank you very much - ran into same issue

  • Anonymous
    November 25, 2014
    The comment has been removed

  • Anonymous
    January 08, 2015
    I had the same issue. Ran the snippet from rush222, and started back up debug and it worked. Thanks :)

  • Anonymous
    March 18, 2015
    The comment has been removed