Deploying .NET 4 Project – Error 1001 (System.BadImageFormatException)

After attending the UK Tech Days events last week in London, I was keen to jump on the Visual Studio 2010 and .net 4.0 bandwagon.

I converted some of our projects here at Crocus to the .net 4 framework (which was incredibly easy – nothing broke!)
I even took advantage of some of the quick to implement features in .net 4, and converted some of our massively over-ridden methods to use optional parameters.

One project in particular is a Windows Service, that sends out purchase orders on a schedule.
(I recently wrote about how this broke due to Quartz.net expecting a UTC start time)

This has a Visual Studio deployment project associated with it.

After building the newly upgraded .net 4 version of the project, and deploying the .msi file to our target server, I got the following error:

Error 1001 Exception occurred while initializing the installation. System.BadImageFormatException: Could not load file or assembly or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

Now, I had definitely upgraded said server to .net 4 (twice, as a matter of fact – after the first time i received this error!)

After some Googling, some people were saying to change the platform target on my assemblies, which i did, to no avail.

I eventually discovered the problem.

You need to set the .NET Framework Launch Condition

Here’s how to do it:

Right click on your deployment project in solution explorer

Right click on your deployment project in solution explorer

Under “Version” Choose .NET Framework 4

Under “Version” Choose .NET Framework 4

After rebuilding and deploying my setup file, everything worked fine.


22 Replies to Deploying .NET 4 Project – Error 1001 (System.BadImageFormatException)

  1. Kevin says:

    Thanks. You saved me a few hours of headache! :D

  2. Drew says:

    Yeah, no kidding. The worst part is that it shows as an error when you open up the launch conditions, but the compiler doesn’t report an error.

  3. Thanks for the information, I havea windows service that I have migrated from .NET 3.5 to .NET 4.0 and this was such an obscure error. I had triple checked the version on the server five times at least and was not lookig forward to spending the day troubleshooting this.

    Thanks again
    Mark

  4. Kevin.Gu says:

    Thanks very much! :D

  5. flashenoise says:

    Thanks for sharing, good article.

    In addition, in same cases when you’re changing launch conditions, make sure that selected options in prerequisites (Setup Properties > Prerequisites) match against selected framework.

  6. jitbit says:

    Thanks! You’ve ended my 2-days headache

  7. Andre says:

    you saved me a great deal of time, my service i made up of about 20 class projects all with their own references, going through them once was time consuming enough, let alone doingit again

    many thanks !!!

  8. Mike says:

    Many thanks for this worked like a charm.

  9. Steve says:

    Many thanks, spent ages trying to figure this out before reading your solution.

  10. Lake says:

    Thanks – so glad you found the problem and published it for the rest of us.

  11. Demetrios Vasiadis says:

    WOW. Thanks for this post. Spent hours trying to figure out why this was happening. +1 for the simple fix.

  12. mike says:

    Thank you! This post is a nugget of gold. You save me a bunch of time trying to track this down

  13. Patrick says:

    You Da Man! Thanks!

  14. paul smietan says:

    Thank you – worked like a charm and you saved me a ton of time!

  15. ehsan says:

    my problem solved. thanks a lot.
    but there is a question:
    I create a sample project in .net4 and create a setup for it.
    the .net version in launch condition was .net 4 by default.
    but this error occurred!!! why?

  16. Shawn says:

    I did what you said to try but I’m still having the same issue. Do you have any other suggestions?

  17. Fernando says:

    Thanks to publish this, works for me. :)

  18. Abbie says:

    Absolutely brilliant. Thank you.

  19. Atiya says:

    Well done! it worked for me too :)

  20. Yassir says:

    Thanks. That’s how posts should be, straight to the point.

Leave a Reply