Build for .NET Framework 4

Sep 14, 2015 at 2:29 PM
When I try to run installer that was built for .NET Framework 4 I get exception

SFXCA: Binding to CLR version v2.0.50727
Cannot attach ManagedUI: System.BadImageFormatException: Could not load file or assembly 'InstallBuilder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'InstallBuilder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
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.Reflection.Assembly.Load(String assemblyString)
at WixSharp.ManagedProject.GetDialog(String info, Boolean validate)
at WixSharp.ManagedProject.<>c.<ReadDialogs>b__22_2(String x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList(IEnumerable
1 source)
at WixSharp.ManagedProject.ReadDialogs(String data)
at WixSharp.ManagedUI.ReadDialogs(Session session)
at WixSharp.ManagedUI.Initialize(Session session, String resourcePath, InstallUIOptions& uiLevel)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value .

Exception thrown by embedded UI initialization:
System.BadImageFormatException: Could not load file or assembly 'InstallBuilder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
File name: 'InstallBuilder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
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.Reflection.Assembly.Load(String assemblyString)
at WixSharp.ManagedProject.GetDialog(String info, Boolean validate)
at WixSharp.ManagedProject.<>c.<ReadDialogs>b__22_2(String x)
at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList(IEnumerable
1 source)
at WixSharp.ManagedProject.ReadDialogs(String data)
at WixSharp.ManagedUI.ReadDialogs(Session session)
at WixSharp.ManagedUI.Initialize(Session session, String resourcePath, InstallUIOptions& uiLevel)
at Microsoft.Deployment.WindowsInstaller.EmbeddedUIProxy.Initialize(Int32 sessionHandle, String uiClass, Int32 internalUILevel)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value .

What wrong?
Coordinator
Sep 15, 2015 at 12:30 AM
Edited Sep 15, 2015 at 6:14 AM
ManagedUI is built on top of MSI/WiX Embedded UI model, which unfortunately has a limitation - it can only consume up to .NET v3.5 compiled assemblies.

You can read more about it here: https://wixsharp.codeplex.com/wikipage?title=Deployment%20scenarios#_embedded_ui_limitations

However MSI/WiX Managed Custom Actions model isn't affected by this limitation. Thus while ManagedUI assembly has to be a v3.5 assembly you can easily place your custom actions into v4.0+ assembly and consume it as an external custom action container (see DTF_ExternalAssembly sample for details).

BTW this WiX issue is logged on their tracking system: http://wixtoolset.org/issues/4891/
Marked as answer by keshunja on 9/15/2015 at 4:58 AM
Sep 15, 2015 at 11:58 AM
Thanks for help. I have moved custom actions to separate assembly.

But I'm little confused with path resolving. If path (for example custom action assembly) is relative Wix# try to resolve it with base project.SourceBaseDir. But I think more obvious to use current dir (where run exe).
Coordinator
Sep 16, 2015 at 6:03 AM
> But I think more obvious to use current dir (where run exe).
Yes it is possible but you are no longer required to solve your problem this way. As WiX team pointed out the problem problem is caused by MakeSfxCA.exe accepting and ignoring the misnamed config file. Thanks to their support the fix/work-around became possible.

The latest release v1.0.26.0 allows both EmbeddedUI and Custom Actions to be compiled for .NET 4.0. All ManagedSetup samples are also updated to target .NET 4.0.