Alex

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

April 26, 2010

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.



TAGS: - -


# Back

  • Kevin

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

  • Drew

    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.

  • http://www.e-evolution.net Gold Coast Software Development, Australia

    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

  • Kevin.Gu

    Thanks very much! :D

  • flashenoise

    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.

  • http://blog.jitbit.com/ jitbit

    Thanks! You’ve ended my 2-days headache

    • http://www.alexjamesbrown.com Alex

      No problem-
      That’s about how long i spent on this!

  • http://www.lowcarboneconomy.com Andre

    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 !!!

  • Mike

    Many thanks for this worked like a charm.

  • Steve

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

  • http://eyasco.com Lake

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

  • Demetrios Vasiadis

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

  • mike

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

  • http://www.yourlifetools.com Patrick

    You Da Man! Thanks!

  • paul smietan

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

  • ehsan

    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?

  • S

    Thanks!!!

  • Shawn

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

  • Fernando

    Thanks to publish this, works for me. :)

  • Abbie

    Absolutely brilliant. Thank you.

  • Atiya

    Well done! it worked for me too :)

  • Yassir

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

  • PeterJ

    After trying a few other people’s suggestions this was the one that worked.
    Many thanks!

  • ShivaA

    This is very useful.

  • MikeJ

    It’s July 2012 and your post is still saving people (me) headaches. Thanks great post!

  • Mysterious

    Thanks a Zillion…. :)

  • Jim

    Any reason why? All my projects are built against the .NET Framework 4 Client Profile. Why should the installer need the full .NET Framework 4?

    Actually, it didn’t work for me. I still see the same error when I try to install it.

  • John

    Thank you for posting! Saved me loads of time.

  • opherko

    Thanks for this post, it was just what I needed after converting an old app to 4.0 and not knowing what the deal was. Since there are multiple referenced assemblies I had incorrectly assumed it was a cross between target platforms in the assemblies, but not so.

    Preesh!

  • max

    Perfect!

  • savari

    Thank you Sooooooooooooooooo much…

  • Mauri

    CAPO!!!

  • Taraby

    Many Thanks ,,

  • Andy M

    Thank you very much. Finally a resolution to this issue. You can claim your pint when next you are in the Knaphill area.