Monday, July 19, 2010

Help! My .NET Setup Package Is Throwing a System.BadImageFormatException Error 1001

Recently I had a WCF service install package that was upgraded from VS.NET 2008 to VS.NET 2010 fail with the following error message upon installing it locally on my machine:

"Product: MyWCFService -- Error 1001. Error 1001. Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files\MyApps\WCFServices\MyWCFService.WinServiceHost.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.."


You might also see the following warning issues by the compiler:

"The target version of the .NET Framework in the project does not match the .NET Framework launch condition version '3.5.30729 '. Update the version of the .NET Framework launch condition to match the target version of the.NET Framework in the Advanced Compile Options Dialog Box (VB) or the Application Page (C#, F#)."

Well this was interesting to me because this was being displayed on a machine that has everything: .NET Framework 4.0, tools, you name it. There should be nothing missing. That's the 1st place to start obviously - make sure the .NET Framework is installed on the target machine.

However this was not the case in my scenario. It turns out even though all of my project comprising the setup package targeted the .NET Framework 4.0, and even the Setup package prerequisites indicated the .NET Framework 4.0, there was still 1 piece of the puzzle missing.

The problem: under the "Detected Dependencies" list for the setup project the 1st item listed was "Microsoft .NET Framework". Refreshing the dependencies does nothing for this value; it must be reconfigured manually. Double click the "Microsoft .NET Framework" item to bring up the "Launch Conditions" window and properties. In the 'Properties' window, change the 'Version' attribute to .NET Framework 4.0 (or whichever framework for your scenario). The Launch Conditions window is displayed below. After making the change, the installer package worked perfectly and installed without issues.



12 comments:

  1. Well, THAT would have taken me a long time to find in the VS interface! Thanks for your post. I'm assuming some kind of .NET patch threw the versions out of kilter; my error message actually said "...does not match the .NET Framework launch condition version 3.5.21022" so I'm assuming it's not specific to the version you mention in your post.

    ReplyDelete
  2. Nice find. I had this problem when upgrading a Visual Studio 2008 project to 2010. The targeted framework version was '3.5.30729' and just needed to be changed to '.NET Framework 3.5'. This article saved me a lot of lost time!

    ReplyDelete
  3. Thank you very much, this saved me a lot of time.

    ReplyDelete
  4. Worked for me. Thanks!

    ReplyDelete
  5. Tonight this saved me lots of headache. Thanks,

    ReplyDelete
  6. This resolved the initial error as described in your post, but a subsequent warning was generated: "WARNING: The version of the .NET Framework launch condition '.NET Framework 4' does not match the selected .NET Framework bootstrapper package. Update the .NET Framework launch condition to match the version of the .NET Framework selected in the Prerequisites Dialog Box."

    To resolve this one, you need to select the Installer Project > right click > properties > prerequisites and then correct which version should be selected (should be the same as in the Launch Condition Properties).

    ReplyDelete
  7. You saved my day! Thanks.

    ReplyDelete
  8. I had this error after upgrading my project from 2008 to 2010 Specificly the to target dot net 4.0. Even after updating the installer dependency the warning still kept popping up. To resolve it I had to close and reopen the project. Strange piece of cached info maybe that's why the autodetect didn't work either.

    ReplyDelete
  9. Thank you very much. While my problem wasn't completely solved by this, it sure did help.

    After having this issue today too, I followed some of the advice in this post and then looked a little deeper at the actual project file configuration (.vdproj file) and located where the problem was. It seems that both Debug and Release configurations both have to be configured correctly otherwise you will get this warning. I have outlined all the steps to prevent this warning below.

    I was getting the following warning:-

    WARNING: The version of the .NET Framework launch condition '.NET Framework 4' does not match the selected .NET Framework bootstrapper package. Update the .NET Framework launch condition to match the version of the .NET Framework selected in the Prerequisites Dialog Box.

    To stop this error from occuring you need to follow the following steps to ensure eveything is targetting the same framework:-

    1.For the main project, right-click the project and go to Properties
    2.Click the Application tab and select the correct Target Framework, save and close
    3.Click on the Setup Project and open the Launch Conditions Editor
    4.Right-Click the Framework launch condition and select 'Properties Window'
    5.In the 'Version' property select the same version that you selected as the Target Framework for the main project
    6.Right-Click the Setup Project and select 'Properties'
    7.At the top you will see a 'Configuration' drop-down box, select Debug and then click on the 'Prerequisites' button
    8.Select the same framework that you selected as the 'target framework' in the main project
    9.Click Apply
    10.In the 'Configuration' drop-down box, select Release and then click on the 'Prerequisites' button
    11.Select the same framework that you selected as the 'target framework' in the main project
    12.Click Ok
    Build the setup project and the warning should now have disappeared - I found the last steps (8-12) solved my issue and saves having to directly modify the .vdproj file manually.

    NOTE: in the 'Configuration' drop-down box you do have the option of selecting 'All Configurations', however, I found that doing this and then picking the prerequisites caused Visual Studio 2010 to crash...

    Reference:
    http://social.msdn.microsoft.com/Forums/en/winformssetup/thread/5167197a-12a5-473e-940a-569e92f08f37 -- Will Foster

    ReplyDelete
  10. got the same problem after upgrading a solution from VS2008 to VS2010.
    Your find saved me a ton of time!
    Thanks!

    ReplyDelete
  11. Same problem in VS2013,
    Your post is still providing value!

    Thanks!

    ReplyDelete