BadImageFormatException .NET Origin: Application & API OSI layer 7 · Application Last updated 2 Dec 2026

System.BadImageFormatException: Could not load file or assembly — An attempt was made to load a program with an incorrect format

The runtime tried to load an assembly or native DLL built for a different architecture or runtime.

Exact message you may see An attempt was made to load a program with an incorrect format
Seen on: .NET

Meaning

Typical mix-ups are x86 vs x64 vs ARM64, a native DLL loaded by managed code of another bitness, or a .NET Framework assembly loaded where .NET Core is expected.

Common causes

  • x86 process loading an x64 DLL (or the reverse)
  • Wrong platform target (AnyCPU "Prefer 32-bit")
  • Native dependency of the wrong architecture
  • Corrupt or truncated DLL

⚡ Quick fix

  1. Build all projects for the same platform (x64)
  2. Use the matching native library (runtimes/win-x64/native)
  3. Check the DLL with dumpbin /headers or corflags

Detailed fix by platform

Visual Studio

  1. Project → Properties → Build → Platform target

CLI

  1. dotnet publish -r win-x64 --self-contained false

How to diagnose

  1. Bitness — Process vs DLL?
  2. Target — AnyCPU/x86/x64?
  3. Native — Right runtime folder?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.