[wix-users] Bad Image Format Exception

Edwin Castro egcastr at gmail.com
Thu Nov 16 09:23:12 PST 2017


The MSDN documentation for BadImageFormatException has a nice list of
reasons why you might get this exception. See the Remarks section:

https://msdn.microsoft.com/en-us/library/system.badimageformatexception.aspx

I see six different reasons listed there. One of them happens to be my
suggestion:

"Your application’s components were created using different versions of the
.NET Framework. Typically, this exception occurs when an application or
component that was developed using the .NET Framework 1.0 or the .NET
Framework 1.1 tries to load an assembly that was developed using the .NET
Framework 2.0 SP1 or later, or when an application that was developed using
the .NET Framework 2.0 SP1 or .NET Framework 3.5 tries to load an assembly
that was developed using the .NET Framework 4 or later. The
BadImageFormatException may be reported as a compile-time error, or the
exception may be thrown at run time."

Check the other five reasons to see if your situation matches one of those.

MSDN also has a troubleshooting page for BadImageFormatException:

https://msdn.microsoft.com/en-us/library/k7137bfe.aspx

> --------------------------------------------------------------
> Calling custom action
> WixDbInstall!HSalimCo.CustomActions.EnumerateSqlServers
> Error: could not load custom action class HSalimCo.CustomActions from
> assembly: WixDbInstall
> System.BadImageFormatException: Could not load file or assembly
> 'WixDbInstall' or one of its dependencies. This assembly is built by a
> runtime newer than the currently loaded runtime and cannot be loaded.

This says explicitly that the CA DLL is targeting a newer runtime than the
one that is loading the CA DLL. One possible reason for this could be that
the newer runtime is not actually installed. Another reason could be that
the newer runtime is not getting used. If you have indeed verified that the
newer runtime is actually installed on the target system then maybe the
config file is not getting included when your build process or the IDE is
calling MakeSfxCA.exe. That might explain why <supportedRuntime
version="v4.0" /> didn't seem to have an effect.

--
Edwin G. Castro


On Wed, Nov 15, 2017 at 4:36 PM, Habib Salim <habib at hsalim.com> wrote:

> Edwin,
>
> Thanks.
>
> I am certain that the framework exists.  It is on windows10.  And, I have
> been testing the installer on the same machine all through.
>
>
>
>
>
> *From:* Edwin Castro [mailto:egcastr at gmail.com]
> *Sent:* Wednesday, November 15, 2017 7:20 PM
> *To:* WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
> *Cc:* Habib Salim <habib at hsalim.com>
> *Subject:* Re: [wix-users] Bad Image Format Exception
>
>
>
> Are you certain that the target framework for your CA is installed on the
> target system? If you are targeting 4.5 but 3.5 is installed, then it would
> make sense to get the BadImageFormatException...
>
>
>
> --
> Edwin G. Castro
>
>
>
>
>
> On Wed, Nov 15, 2017 at 11:18 AM, Habib Salim via wix-users <
> wix-users at lists.wixtoolset.org> wrote:
>
> Something just occurred to me - I recently decided to sign the assembly
> and the installer.
> I guess just around the time I started getting this error.
> Could that be the cause?
>
> Although I have a workaround, I can't stop trying to find out what caused
> the issue.  Can't have it flaking out when it is out in the market.
>
>
>
> -----Original Message-----
> From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf
> Of Joseph L. Casale via wix-users
> Sent: Wednesday, November 15, 2017 1:52 PM
> To: 'WiX Toolset Users Mailing List' <wix-users at lists.wixtoolset.org>
>
> Cc: Joseph L. Casale <jcasale at activenetwerx.com>
> Subject: Re: [wix-users] Bad Image Format Exception
>
> -----Original Message-----
> From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf
> Of Habib Salim via wix-users
> Sent: Wednesday, November 15, 2017 11:03 AM
> To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
> Cc: Habib Salim <habib at hsalim.com>
> Subject: Re: [wix-users] Bad Image Format Exception
>
> > I finally figured it out.  the Custom Action project should use .Net
> > Framework 3.5 as the target framework.
> > (FW3.0 and 2.0 may also work; I haven't tried).  FW4.0 and above
> > changes the runtime to 4.0 causing the BadImageFormatException.
>
> I was paying attention to your post as I have seen that before but failed
> to recall how I resolved it. I assure you the CA project does not need to
> target 3.5, that simply resolved your issue somehow but it is not a
> requirement.
>
> I am currently in working in a large project with countless CAs and the
> solution is targeting 4.6.2.
>
> jlc
>
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant
> http://www.firegiant.com/
>
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant
> http://www.firegiant.com/
>
>
>



More information about the wix-users mailing list