Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: An attempt was made to load a program with an incorrect format #84

Open
Douuuglas opened this issue Jan 29, 2020 · 10 comments
Open

Comments

@Douuuglas
Copy link

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

image

System where it's not working

image

System where it's working

image

@jeffkl
Copy link
Owner

jeffkl commented Feb 3, 2020

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.

@Douuuglas
Copy link
Author

I tried both, none have worked. Wich archecture is the nuget of ManagedDism compiled with?

@Douuuglas
Copy link
Author

I've downloaded the source, built with Any CPU and imported into my project and it worked!

@jeffkl
Copy link
Owner

jeffkl commented Feb 20, 2020

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?

@Douuuglas
Copy link
Author

That's really weird!
I haven't modified, i've just downloaded the master branch and built with Any CPU option 🤔

@jeffkl
Copy link
Owner

jeffkl commented Feb 26, 2020

Can you please attach your locally built Microsoft.Dism.dll so I can do a comparison?

@Douuuglas
Copy link
Author

Sure!

Here it is:
Microsoft.Dism.dll.zip

@jeffkl
Copy link
Owner

jeffkl commented Feb 27, 2020

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?

@ConnorChristie
Copy link

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

@fondencn
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants