Dotnet 5.0 project referencing 64bit dll runs locally but elsewhere throws "An attempt was made to load a program with an incorrect format."


I am referencing a third party dll that has both x64 and x86 versions. I am using the x64 version. There are no build warnings about mismatched bitness. This project runs fine from Visual Studio and running the .exe from the build folder on my local Windows 10 x64 machine, but when running on another machine with a clean Windows 10 x64 installation, however, as soon as the code that uses the referenced dll is hit, an error is thrown. I have spun up a Windows 10 x64 VM and can reproduce the problem there so it is not specific to any machine. My conclusion is that I have something installed on my machine that is allowing the program to behave correctly but that something is not installed on the other machines.

An attempt was made to load a program with an incorrect format.

I have tried switching the project platform to be x86 and reference the x86 version of the third part dll but get the same results.

Below is the project file.


Here is the full exception. The SATOPrinterAPI is the referenced dll. It looks like maybe the dll is loading another assembly that is having the issues.

 System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (0x8007000B)
     at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
     at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
     at System.Reflection.Assembly.LoadFile(String path)
     at SATOPrinterAPI.EmbeddedAssembly.Load(String Resouces, String FileName)
asked on Stack Overflow May 15, 2021 by Dennis Kiesel • edited May 16, 2021 by Dennis Kiesel

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0