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.