17

We were using WIX 3.5 (Build Number 1811) and built a custom action built using Visual Studio 2008 and with target framework as .Net 3.5. This used to work great, until we built the custom action using Visual Studio 2010 and with target framework as .Net 4.0.

WIX is unable to invoke the custom action, the error that we get is this:

  SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI69BD.tmp-\
    SFXCA: Binding to CLR version v2.0.50727
    Calling custom action SomeCompany.SomeProduct.InstallerPlugin!SomeCompany.SomeProduct.InstallerPlugin.XYZProductCustomAction.ABCMethod
    Error: could not load custom action class SomeCompany.SomeProduct.InstallerPlugin.XYZProductCustomAction from assembly: SomeCompany.SomeProduct.InstallerPlugin

    System.BadImageFormatException: Could not load file or assembly 'SomeCompany.SomeProduct.InstallerPlugin' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    File name: 'SomeCompany.SomeProduct.InstallerPlugin'
       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)
coder_bro
  • 10,503
  • 13
  • 56
  • 88

5 Answers5

29

Just my two cents:

Unlike Ngm I only had to add supportedRuntime for .NET 4.0

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
</configuration>

Important:

  1. Don't rename CustomAction.config
  2. Set the CustomAction.config Build Action to Content, else it won't work
Denys Wessels
  • 16,829
  • 14
  • 80
  • 120
  • 8
    Also make sure you don't rename CustomAction.config – Schalk Jan 16 '13 at 13:31
  • 3
    Yes! Thank you! This fixed my problem. The Build Action is incredibly important! Why isn't this more prominent in this question ? – Alex Marshall Jun 17 '13 at 19:46
  • 3
    I was curious why CustomAction.config absolutely had to be named that. In the WiX 3.7 source in SfxCA.cpp you can see them using "CustomAction.config" as a hardcoded string. I played around and it seems you can name your custom action assembly, class, functions, and namespaces be whatever you want, but it must have a config file named exactly "CustomAction.config" set to Content. – Walter Wilfinger Nov 04 '13 at 17:17
  • Thank you for mentioning that you should not (cannot) rename 'CustomAction.config', this was the critical key to resolving my issue. – HidekiAI May 01 '15 at 15:45
  • Just for the records, the file must be named CustomAction.config and Build Action set to Content. If you incidentally deleted it and then you re add a config file, it MUST be renamed. – Oscar May 03 '17 at 12:54
7

Well we finally resolved the problem, we had to set:

useLegacyV2RuntimeActivationPolicy="true"
and
have both versions specified:
<supportedRuntime version="v2.0.50727"/>
and
<supportedRuntime version="v4.0"/>

If just "<supportedRuntime version="v4.0"/> is specified, it does not work. So looks like a bug in WIX 3.5 Beta

coder_bro
  • 10,503
  • 13
  • 56
  • 88
  • 1
    Thanks this helped. Although in my case, I did not need the v2 supportedRuntime element. Having just v4 worked fine. – Rick Glos Aug 11 '10 at 20:24
  • 2
    Also, make sure you do not rename the CustomAction.config file; otherwise, the settings will not take effect. – Alek Davis May 10 '13 at 22:45
2

There is a bug open to tweak the DTF supportedRuntime element in its manifest to support NETFX 4.0. That bug hasn't been fixed yet so you need still to do it yourself.

Rob Mensching
  • 33,834
  • 5
  • 90
  • 130
1

Thanks for this nice post. Its solved my query. In my case error was I have renamed config file and now restored it to original.

Anna
  • 41
  • 7
1

Additionally to the solution from Ngm we had to set the target framework of the managed custom action class library back to .NET 2.0 to get things working.

menty
  • 416
  • 3
  • 6