Rimer
Rimer

Reputation: 2074

WIX installer with Custom Actions: "built by a runtime newer than the currently loaded runtime and cannot be loaded."

I have a WIX installer that executes Custom Actions over the course of install. When I run the WIX installer, and it encounters its first Custom Action, the installer fails out, and I receive an error in the MSI log as follows:

Action start 12:03:53: LoadBCAConfigDefaults. SFXCA: Extracting custom action to temporary directory: C:\DOCUME~1\ELOY06~1\LOCALS~1\Temp\MSI10C.tmp-\ SFXCA: Binding to CLR version v2.0.50727 Calling custom action WIXCustomActions!WIXCustomActions.CustomActions.LoadBCAConfigDefaults Error: could not load custom action class WIXCustomActions.CustomActions from assembly: WIXCustomActions System.BadImageFormatException: Could not load file or assembly 'WIXCustomActions' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. File name: 'WIXCustomActions' at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) at System.AppDomain.Load(String assemblyString) at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.GetCustomActionMethod(Session session, String assemblyName, String className, String methodName)

... the specific problem from above is "System.BadImageFormatException: Could not load file or assembly 'WIXCustomActions' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

The wordage of that error seems to indicate something like an incorrectly referenced .NET framework or something (I'm targeting 3.5 in both my custom actions and its dependencies), but I can't figure out where to make a change to address this problem. Any ideas?

.... Not sure if this will help but it's the CustomActions package batch file I run to create the .dll package containing the custom action functions:

===============

call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"

@echo on

cd "C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions"

csc /target:library /r:"C:\program files\windows installer xml v3.6\sdk\microsoft.deployment.windowsinstaller.dll" /r:"C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\eLoyalty.PortalLib.dll" /out:"C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\WIXCustomActions.dll" CustomActions.cs

cd "C:\Program Files\Windows Installer XML v3.6\SDK"

makesfxca "C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\BatchCustomerAnalysisWIXCustomActionsPackage.dll" "c:\program files\windows installer xml v3.6\sdk\x86\sfxca.dll" "C:\development\trunk\PortalsDev\csharp\production\Installers\WIX\customactions\PAServicesWIXCustomActions\bin\Debug\WIXCustomActions.dll" customaction.config Microsoft.Deployment.WindowsInstaller.dll

Upvotes: 4

Views: 5504

Answers (6)

yellow_submarine
yellow_submarine

Reputation: 152

I had a WiX v3.11 project which I recently moved to v4.

The error was happening after the migration because I forgot to add the CustomAction.config file into the Custom Action project.

Make sure you have a CustomAction.config file and do not change its name!

This file has to have Visual Studio > Properties > Build Action set to Content.

One typical example of this file follows below.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">

    <!--
      Use supportedRuntime tags to explicitly specify the version(s) of the .NET Framework runtime that
      the custom action should run on. If no versions are specified, the chosen version of the runtime
      will be the "best" match to what Microsoft.Deployment.WindowsInstaller.dll was built against.

      WARNING: leaving the version unspecified is dangerous as it introduces a risk of compatibility
      problems with future versions of the .NET Framework runtime. It is highly recommended that you specify
      only the version(s) of the .NET Framework runtime that you have tested against.

      Note for .NET Framework v3.0 and v3.5, the runtime version is still v2.0.

      In order to enable .NET Framework version 2.0 runtime activation policy, which is to load all assemblies
      by using the latest supported runtime, @useLegacyV2RuntimeActivationPolicy="true".

      For more information, see http://msdn.microsoft.com/en-us/library/bbx34a2h.aspx
    -->

    <supportedRuntime version="v4.0" />
    <supportedRuntime version="v2.0.50727"/>

  </startup>

<!--
  Add additional configuration settings here. For more information on application config files,
  see http://msdn.microsoft.com/en-us/library/kza1yk3a.aspx
-->

  <!-- The snippet below was transplanted from the app.config file. -->
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

Upvotes: 1

gigi
gigi

Reputation: 916

I had a similar problem but with .net 4.6 My custom dll is built with .net 4.6 but if it's not installed the package fails as described above. The problem for me was that the custom action was running before the condition to check if .net 4.6 is installed. So I changed the code to this:

<Custom Action="MyCustomAction" After="LaunchConditions">

Upvotes: 0

Vladimirs
Vladimirs

Reputation: 8619

This happens when referenced Custom Action targets framework that is not installed.

So you can either change Target Framework of your custom action project if possible, or check for .NET Framework Version.

Upvotes: 0

Charles Janik
Charles Janik

Reputation: 1

Check that the launch conditions for the MSI project are showing the correct .net version

Upvotes: 0

Rimer
Rimer

Reputation: 2074

I FIXED IT!

The problem is that the csc that was running during the package.bat file was actually the 2.0 version of the framework...

I changed the batch file to run the one that lives in the c:\WINDOWS\Microsoft.NET\v3.5\ from the one that was in the v2.0.xxxxx folder and it works now without throwing this error..

Upvotes: 1

Dirk Vollmar
Dirk Vollmar

Reputation: 176249

The BadImageFormatException is most likely indicating that there is a mismatch between x86 and x64 code in your installer.

If your MSI is 32-bit, make sure the platform target of your custom action project is set to x86, otherwise, if your installer is a 64-bit one, set it to x64.

Upvotes: 1

Related Questions