'Could not load file or assembly' error when calling Heat (WiX) from within MSBuild

igoravl's Avatar

igoravl

03 Aug, 2015 06:04 PM

Has anyone seen this before?

I have an VS solution with a WiX project, which in turn has a <HeatDirectory> MSBuild taks ('HeatDirectory' is a WiX built-in MSBuild taks). Running my AppVeyor build locally (i.e. running locally the same PowersShell script that is run by AppVeyor) everything works as expected, However, on AppVeyor I get the following error:

[00:02:00] Project "C:\projects\tfscmdlets\TfsCmdlets\TfsCmdlets.Setup\TfsCmdlets.Setup.wixproj.metaproj" (2) is building "C:\projects\tfscmdlets\TfsCmdlets\TfsCmdlets.Setup\TfsCmdlets.Setup.wixproj" (4) on node 1 (default targets).
[00:02:00] BeforeBuild:
[00:02:00] C:\Program Files (x86)\WiX Toolset v3.9\bin\Heat.exe dir C:\projects\tfscmdlets\TfsCmdlets\\TfsCmdlets\Bin\Release -cg ModuleComponent -dr INSTALLDIR -scom -sreg -srd -var var.SourceDir -ag -out obj\Release\_ModuleComponent_dir
[00:02:00] .wxs
[00:02:00] Could not load file or assembly 'file:///C:\Program Files (x86)\WiX Toolset v3.9\bin\Heat.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.
[00:02:01] at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boo
[00:02:01] lean forIntrospection, Boolean suppressSecurityChecks)
[00:02:01] at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound,
[00:02:01] Boolean forIntrospection, Boolean suppressSecurityChecks)
[00:02:01] at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection
[00:02:01] , Boolean suppressSecurityChecks)
[00:02:01] at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCraw
[00:02:01] lMark& stackMark)
[00:02:01] at System.Reflection.Assembly.LoadFrom(String assemblyFile)
[00:02:01] at Microsoft.Tools.WindowsInstallerXml.Build.Tasks.WixToolTask.ExecuteToolThread(Object parameters)
[00:02:01] Error: 8/3/2015 5:41:17 PM:
[00:02:01] At C:\projects\tfscmdlets\TfsCmdlets\psake-default.ps1:70 char:12 + exec { MSBuild.exe '--%' $MSBuildArgs }

When I saw the "An attempt was made to load a program with an incorrect format" error message, I assumed it could be a case of bitness mismatch (MSBuild x64 loading a WiX x86 assembly or vice-versa) but after checking the PATH env var in the build server it seems not to be the case: MSBuild is listed as 'C:\Program Files (x86)\MSBuild\12.0\Bin' in PATH, so, I guess it is x86. Same applies to WiX, located at C:\Program Files (x86)\WiX Toolset v3.9.

Well, I ran out of guesses :)

Does anyone have an idea on why it's broken?

AppVeyor project: https://ci.appveyor.com/project/igoravl/tfscmdlets/
GitHub repo: https://github.com/igoravl/tfscmdlets

Thanks in advance,
    Igor

  1. 1 Posted by igoravl on 03 Aug, 2015 07:57 PM

    igoravl's Avatar

    Adding some further information: after collecting Fusing binding logs, it seems MSBuild is running as x64 (notice line below, "Running under executable C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe", pointing to Framework64 folder):

    *** Assembly Binder Log Entry  (8/3/2015 @ 7:27:37 PM) ***
    
    The operation failed.
    Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.
    
    Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
    Running under executable  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
    --- A detailed error log follows. 
    
    === Pre-bind state information ===
    LOG: Where-ref bind. Location = C:\Program Files (x86)\WiX Toolset v3.9\bin\Heat.exe
    LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/
    LOG: Initial PrivatePath = NULL
    LOG: Dynamic Base = NULL
    LOG: Cache Base = NULL
    LOG: AppName = MSBuild.exe
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in LoadFrom load context.
    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
    LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe.Config
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Attempting download of new URL file:///C:/Program Files (x86)/WiX Toolset v3.9/bin/Heat.exe.
    LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\WiX Toolset v3.9\bin\Heat.exe
    LOG: Entering run-from-source setup phase.
    LOG: Assembly Name is: heat, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ce35f76fcda82bad
    ERR: Invalid assembly platform or ContentType in file (hr = 0x8007000b).
    ERR: Run-from-source setup phase failed with hr = 0x8007000b.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
    
    *** Assembly Binder Log Entry  (8/3/2015 @ 7:27:37 PM) ***
    
    The operation failed.
    Bind result: hr = 0x8007000b. An attempt was made to load a program with an incorrect format.
    
    Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
    Running under executable  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
    --- A detailed error log follows. 
    
    === Pre-bind state information ===
    LOG: Where-ref bind. Location = C:\Program Files (x86)\WiX Toolset v3.9\bin\Heat.exe
    LOG: Appbase = file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/
    LOG: Initial PrivatePath = NULL
    LOG: Dynamic Base = NULL
    LOG: Cache Base = NULL
    LOG: AppName = MSBuild.exe
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in LoadFrom load context.
    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
    LOG: Using application configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe.Config
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Attempting download of new URL file:///C:/Program Files (x86)/WiX Toolset v3.9/bin/Heat.exe.
    LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\WiX Toolset v3.9\bin\Heat.exe
    LOG: Entering run-from-source setup phase.
    LOG: Assembly Name is: heat, Version=3.0.0.0, Culture=neutral, PublicKeyToken=ce35f76fcda82bad
    ERR: Invalid assembly platform or ContentType in file (hr = 0x8007000b).
    ERR: Run-from-source setup phase failed with hr = 0x8007000b.
    ERR: Failed to complete setup of assembly (hr = 0x8007000b). Probing terminated.
    

    How do I force MSBuild x86 to be used? I tried to set env var Platform to x86, to no avail. After googling for a while, it seems that invoking a x86 PowerShell would do the trick too, but I couldn't find a way to instruct AppVeyor to use a x86 PowerShell.

    Any ideas?

  2. Support Staff 2 Posted by Feodor Fitsner on 03 Aug, 2015 10:04 PM

    Feodor Fitsner's Avatar

    Have you tried adding something like:

    set PATH=C:\Windows\Microsoft.NET\Framework\v4.0.30319;%PATH%
    
  3. 3 Posted by igoravl on 03 Aug, 2015 11:03 PM

    igoravl's Avatar

    Feodor, thanks for following up. I found a workaround, though I don't quite understand whtá going on.

    My wixproj file has these two imports:

    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' AND '$(MSBuildExtensionsPath32)' != '' ">$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    <WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
    

    For some reason it's resolving to #1, even though it's running under MSBuild x64. By disabling the first line (thus forcing x64) it now works.

    Thanks for the help. If I eventually find anything else I'll post it here for the record, in case others have the same issue.

    Cheers,
    Igor

  4. Support Staff 4 Posted by Feodor Fitsner on 03 Aug, 2015 11:07 PM

    Feodor Fitsner's Avatar

    OK, thanks for the update!

  5. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:58 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac