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

Under “Version” Choose .NET Framework 4

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

Thanks. You saved me a few hours of headache!
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.
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
Thanks very much!
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.
Thanks! You’ve ended my 2-days headache
No problem-
That’s about how long i spent on this!
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 !!!
Many thanks for this worked like a charm.
Many thanks, spent ages trying to figure this out before reading your solution.
Thanks – so glad you found the problem and published it for the rest of us.
WOW. Thanks for this post. Spent hours trying to figure out why this was happening. +1 for the simple fix.
Thank you! This post is a nugget of gold. You save me a bunch of time trying to track this down
You Da Man! Thanks!
Thank you – worked like a charm and you saved me a ton of time!
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?
Thanks!!!
I did what you said to try but I’m still having the same issue. Do you have any other suggestions?
Thanks to publish this, works for me.
Absolutely brilliant. Thank you.
Well done! it worked for me too
Thanks. That’s how posts should be, straight to the point.