We recently migrated from VS2003 to VS2005. We have an installer project that calls a custom action from our setup project. It used to work great in VS2003 but VS2005 is giving the following error when the MSI attempts to execute the custom action portion of the setup (occurs at the very end):
Exception occurred while initializing the installation: System.BadImageFormatException: The format of the file "XXCustomAction.dll" is invalid.
In the MSI, our custom action is listed under "Install" as "Primary output from XXCustomAction (Active)". The output shows "XXCustomAction.dll" as the only output. The InstallerClass property is set to True. The Entry Point property is blank. The CustomActionData property contains:
/PATH="[TARGETDIR]\" /WEBSERVER=[WEBSERVER] /VDIR=[VDIR]
Our CustomAction.cs file starts with:
namespace XXCustomAction
{
[RunInstaller(true)]
public class CustomAction : Installer
...
Under the project properties for the custom action, Output Type is set as Class Library. Platform target is set to x86 (also tried Any CPU). All other settings are identical to what we had in VS2003. Any suggestions on why we're getting this error

System.BadImageFormatException executing Custom Action in setup project
JP.
Are you getting this "System.BadImageFormatException" when you are running the MSI
Can you outline in more detail what you are doing exactly.
Robert Schoen (Microsoft Visual Basic QA)
Anon56789
I have the same problem,
my error is
Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:myService.exe' or one of its dependencies. The module was expect
ed to contain an assembly manifest..
This service before the service pack VS80sp1-KB926601-X86-ENU.exe i made withuot problem.
Before I install into w2003r2 standard server without problem,
now after the sp1 any change to the code and rebuild generate in the installation service the problem
that I report.
Help me please
Thanks
Fabio
Andy!
Hi,
Based on my understanding, you have two projects.
1. a installer project, is it a .NET setup project or what is it
2. a .net setup project.
The installer project will call the custom action of setup project. That is to say installer.exe will call the customeraction.dll in the setupproject. Am I right After you migrate the setup project including the custom action dll to VS.NET 2005, you will get the error
If I misunderstood, please feel free let me know.
Simply, I think you may try recreate a .NET 2005 setup project and add the source code(.cs) file into the new project including the files you want to deploy. So to some extent, it should be new pure vs.net 2005 setup project, did the problem persist From the error message, it seems that the customaction.dll is not recognized. So please perform the steps above and let me know the result.
If you still have any concern, please feel free to post here.
Best regards,
Peter Huang
Ed M
I have the same problem with a windows service too. Did you ever solve your problem
Thanks
hosrow
We are seeing this exception too, and like ShaneBattrick reports, we're seeing this exception on some machines only; for rest of the machines the installer runs fine.
I read the causes and environement settings of the reporters on this thread, but in our case certain factors are different:
Some additional data:
Can anyone shed any light on why we would be getting this exception
BTW, the bug filed by Michael Freidgeim here is marked as Closed without giving a reason.
Elkoda
Hi Cconrad,
I am glad your project have working.
If you still have any concern, please feel free to post here.
Best regards,
Peter Huang
Tom D
I created a new custom action project in VS2005. The project type is Class Library. I added one class file of type Installer Class. The only method it contains is the default constructor which calls InitializeComponent().
I removed my previous custom action from the setup project and added a custom action referencing my new custom action project. I'm still receiving the same error.
maheshchinni
I looked into trying to get repro...and the main (simple) way that I could do this is in the VS 2005 project I have the launch condition for the framework set to the 1.1 version of the framework. This will cause this exception at install time.
Here is one specific scenario that I looked at that I believe was raised in this thread:
I take my VS2003 setup project with a class library Custom action project and migrated it to VS2005. On the setup project, I open the Launch Condition editor and select the .net framework. In the properties window, I modified the "version" property back to the 1.1.4322 version that was originally set with the 2003 version. Build the setup and try to install on a machine with V1.1 (and with v2.0 in my case) of the framework and the result is in this exception.....
What happens is by telling the setup that the framework launch condition is 1.1, setup will look for that framework and will use its version of installutil to execute the custom action. In this case the custom action now resides within a 2.0 built assembly. However Installutil and the other framework and sdk tools are not compatible with the "new" versions. In other words, installutil from the 2.0 framework should work fine on 1.1 built assemblies but 1.1 installutil will not work on the 2.0 built assemblies. When this is attempted, you will recieve this badimageformexception error.
I was looking at the bug that was reported to the msdn feedback and will update it accordingly. If you find that you or anyone else is seeing this error without this configuration please let me know. I will monitor this thread and see if there are reports of people hitting this when there is not a launch condition on a framework that is incorrect.
BTW - will be logging an bug regarding having better "actionable" information for the user in this scenario.
Thanks for reporting this issue!
Robert Schoen (Microsoft Visual Basic QA)
lavan
Hi all,
By the way, i also want to know how to create set up project which is uesed for package webpart (MOSS 2007).
Even though i use Reflector to reflect source code CSCustomAction.dll and then i compiled to new CSCustomAction.dll (don't change any code here just added Message at actor of CustomAction.cs) . But when i run msi that the message showed and break down installing. I don't know why Please help me.
Thanks !!!
Bogdan M.
I had the same error with my installer using custom action:
"Exception occurred while initializing the installation:
System.BadImageFormatException: The format of the file 'XXXXX.dll' is invalid.
The reason of the error was that setup project was created in VS 2003 (.Net 1.1) and when converting to VS 2005 the UpgradeCode GUID was left the same.
When I tried to install it on the machine with previous version of the same product installed, it failed.
It seems that it tries to uninstall previous (.Net 1.1) version of the product, but calling custum action using new (.Net 2.0) version of the DLL.
Ther are 2 workarounds:
1. Uninstall previous version of the product prior to install new one.
2. Change UpgradeCode GUID (what cconrad actually done by recreated Setup Project from scratch).
It will allow to have 1.1 and 2.0 versions of your product run in parallel.
I've reported the bug to MSDN Product Feedback Center
Tibor den Ouden
I deleted both projects (again) and recreated everything from scratch in VS2005. I'm not sure why this didn't work the first time, but everything appears to work correctly now. There must have been some VS2003-converted code that carried over the first time I recreated the projects. Thanks for your suggestions.
Tim Daniels
Correct, we have two projects. The first project is a regular Class Library project that generates a DLL. This project contains the custom action code. It contains a CustomAction.cs file containing a public class (called CustomAction) that is derived from System.Configuration.Install.Installer. The class also has the [RunInstaller(true)] attribute. This project was converted from VS2003 to VS2005.
The second project is a .NET setup project. It was created from scratch in VS2005. This project is the one attempting to call the custom action in the previous project. Everything build correctly. The setup project executes correctly until it gets to the very end when it attempts to execute the custom action. The error occurs at this point and the installation is rolled back.
I will try recreating the custom action project in VS2005, hopefully that will resolve the problem.
Jack-Jack
Hi,
I am getting this error eventhough I have build the complete project in Visualstudio 2005 after moving from Visualstudio 2003. The dll was referencing microsoft.reporting services version 8.0. I changed that dll referncing to microsoft.reporting services version 9.0 as visual studio 2005 uses that version there were no build errors but while installing the dll using the installutil under framework 2.0 it's giving me system.bad image format exception.
Can anybody give me any suggestions why it's happening.
regards
Hemant
jinxed
I am experiencing a very similar problem with some slight modifications. I have a Setup Project that was created with VS 2005. When run on one Windows 2003 SP1 box I receive the error "Exception occurred while initializing the installation: System.BadImageFormatException: The format of the file 'Xyz.dll' is invalid.". The oddity here is that it successfully runs on another Windows 2003 SP1 box. I’ve confirmed that the versions of the 2.0 CLR, the MSIEXEC, and the OS are in synch. Has anyone experienced a problem of this nature Are there any suggestions as to how to resolve this Thank you.