ManagedDism
ManagedDism copied to clipboard
Error: An attempt was made to load a program with an incorrect format
First of all: thanks for sharing this well written library!
Situation
I've made an installer with WixSharp, in this installer i validate if the windows machine has the component "WCF-HTTP-Activation" activated. On some machines it's working, but in an azure Windows Server 2012 machine i'm having problems when i execute the code above. See if you can help me!
Here's the code
internal static bool IsHTTActivation35Ativated()
{
try
{
DismApi.Initialize(DismLogLevel.LogErrors);
using (var session = DismApi.OpenOnlineSession())
{
var feature = DismApi.GetFeatureInfo(session, "WCF-HTTP-Activation");
if (feature == null)
return false;
if (feature.FeatureState != DismPackageFeatureState.Installed)
return false;
return true;
}
}
catch
{
return false;
}
finally
{
DismApi.Shutdown();
}
}
Here's the error messages
An attempt was made to load a program with an incorrect format.
StackTrace
at BecomexInstaller.InstallerConfig.PrerequisitesInstallerConfig.IsHTTActivation35Ativated() at Microsoft.Dism.DismUtilities.ThrowIfFail(Int32 hresult, DismSession session)
at Microsoft.Dism.DismSession.Reload()
at Microsoft.Dism.DismApi.OpenOnlineSession()
Project config

System where it's not working

System where it's working

Nothing jumps out, both machines appear to be 64-bit. Can you try unchecking Prefer 32-bit? You might want to just build against x64 instead of Any CPU as well. The exception is only thrown when a 32-bit process tries to load a 64-bit assembly or visa versa.
I tried both, none have worked. Wich archecture is the nuget of ManagedDism compiled with?
I've downloaded the source, built with Any CPU and imported into my project and it worked!
That's really weird, the assembly I published in the NuGet package is Any CPU
// C:\Users\jeffkl\AppData\Local\Temp\9f30a26a-fb72-48bb-b476-fb23fdac0d39\Microsoft.Dism.dll
// Microsoft.Dism, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5bba90053b345501
// Global type: <Module>
// Architecture: AnyCPU (64-bit preferred)
// Runtime: .NET 4.0
I've downloaded the source, built with Any CPU and imported into my project and it worked!
Did you have to modify how Microsoft.Dism.dll was being built?
That's really weird! I haven't modified, i've just downloaded the master branch and built with Any CPU option 🤔
Can you please attach your locally built Microsoft.Dism.dll so I can do a comparison?
That is very bizarre, everything seems to be the same. I'm going to do some minor cleanup and push a new package, maybe that'll work?
We were also getting this same error on previous versions of windows, namely Windows Server 2016 x64. But that was because we were compiling the host application against x86... Not sure why Windows 10 allows it but it works there, just not on older versions.
Solution for me: change application to use x64 or Any CPU
I can confirm the bug report of @ConnorChristie . The exception is thrown on OpenOnlineSession on Windows Server 2016 x64 whilst compiling the host application for win-x86. This is working fine for any flavor of windows 10 and windows server 2012, but throwing on windows server 2016.
I will try @ConnorChristie 's workaround and change to host target to win-x64 for publish.