Tentacle throws BadImageFormatException while loading custom PowerShell task

Hi Paul,
I stuck with the following exception which is thrown during deployment. Be build our sources using property Platform=x86. We can not use AnyCPU because we have some native third-party binaries which are either x86 or x64 but bot both. And we’ve decided to build & deploy our web application as x86 due to some reasons.

I guess Tentacle runs PowerShell x64 and that’s why it can not load x86 assembly. Do you have any idea how to fix the problem?

thanks in advance,

ERROR: Add-Type : Could not load file or assembly ‘file:///C:\Octopus\Tentacle\Applications\Invoicing.Web.UI.\bin\XXXXXXXXXX.Deployment.Tasks.dll’ or one of its dependencies. An attempt was made to load a program with an incorrect format.
ERROR: At C:\Octopus\Tentacle\Applications\Invoicing.Web.UI.\PreDeploy.ps1:1 char:9
ERROR: + Add-Type <<<< -Path ".\bin\XXXXXXXXXX.Deployment.Tasks.dll"
ERROR: + CategoryInfo : NotSpecified: (:slight_smile: [Add-Type], BadImageFormatException
ERROR: + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.AddTypeCommand
ERROR: Unable to find type [XXXXXXXXXX.Deployment.Tasks.WebApplicationManager]: make sure that the assembly containing this type is loaded.
ERROR: At C:\Octopus\Tentacle\Applications\Invoicing.Web.UI.\PreDeploy.ps1:2 char:51
ERROR: + [XXXXXXXXXX.Deployment.Tasks.WebApplicationManager] <<<< ::CreateSubApplication($OctopusWebSiteName) | Write-Host
ERROR: + CategoryInfo : InvalidOperation: (XXXXXXXXXX.Deplo…licationManager:String) [], RuntimeException
ERROR: + FullyQualifiedErrorId : TypeNotFound

Hi Anton,

I haven’t tried but you should be able to have your PowerShell script launch another PowerShell process to call the real script - something like:

& "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe" -File "DeployX86.ps1" | Write-Host

In your package you would have a Deploy.ps1 which contains this line, and a DeployX86 that runs under the 32-bit context to invoke your tasks. That way your script could use a mix of x64 tasks and x86 tasks.

To pass arguments to the script, this page should help:


That’s a workaround. I’ll see what I can do to improve it in future - it might be possible to write a custom function that you can call from within Deploy.ps1 to run it within a x86 context that I can embed in Octopus.

Hope that helps,