0X40000021

STATUS_WX86_EXCEPTION_LASTCHANCE (0x40000021) fix

This error shows up in 32-bit apps on 64-bit Windows. It's a debug message, not a crash. Ignore it or fix it by updating your debugger or app.

Quick answer (for advanced users)

Uncheck "Enable Native Debugging" for managed debuggers, or update your Visual Studio to version 2022 or later. If you're running a 32-bit app outside a debugger, this error is harmless—ignore it.

What this error really means

You're seeing 0x40000021 (STATUS_WX86_EXCEPTION_LASTCHANCE) when debugging a 32-bit application on a 64-bit version of Windows. It's not an application crash. Under the hood, Windows uses the WOW64 subsystem to translate x86 instructions for the 64-bit processor. That translation layer sometimes throws a "last chance" exception—it's a debugger notification that basically says "hey, the emulator got a shot at handling this, and it worked."

I see this mostly with Visual Studio 2019 and earlier when you're debugging C++/CLI mixed-mode applications, or when you run old 32-bit installers under a debugger. The real trigger: the debugger catches the exception before the WOW64 layer swallows it. In production (no debugger attached), you'd never know it happened.

How to fix it

  1. Disable the debugger notification. In Visual Studio, go to Debug > Windows > Exception Settings. Expand Win32 Exceptions. Find 0x40000021 (it might show as STATUS_WX86_EXCEPTION_LASTCHANCE). Uncheck the box. After you apply, the debugger will ignore this exception. You should see the exception list update immediately. If you don't see the entry, you can manually add it: right-click in the Exception Settings window, choose Add Exception, paste 0x40000021 into the code field, and uncheck it.
  2. Update Visual Studio. If you're on VS 2017 or 2019, upgrade to VS 2022. Microsoft cleaned up a lot of these false-positive debugger notifications. After upgrading, the exception may stop appearing without any settings changes.
  3. Switch to native-only debugging. If you're debugging a mixed-mode app (C# calling C++), go to project properties > Debug tab. Uncheck Enable Native Code Debugging. You'll lose the ability to step into native code, but the exception will vanish. Only do this if you don't need to debug the native layer.

Alternative fixes if that doesn't work

  • Use a different debugger. WinDbg handles this exception silently. If you must debug a 32-bit process, try WinDbg (the classic version, not the new Microsoft Store one). Download it from the Windows SDK. After attaching, run sxd vex in the command window to suppress secondary exceptions.
  • Recompile as 64-bit. If you control the source code, target x64. This completely sidesteps WOW64. In Visual Studio, go to Build > Configuration Manager, set Active solution platform to x64. Then rebuild. The error will never appear because the app runs natively on 64-bit Windows.
  • Tweak the registry (advanced, not recommended). Under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WOW64, there's a value called EnableWOW64FSRedirection. Setting it to 0 disables a part of the emulation. I don't suggest this—it breaks 32-bit apps that rely on file system redirection. Only try it if you're testing legacy software in a sandbox.

Prevention tip

If you develop 32-bit applications on a 64-bit Windows machine, always use the latest version of your debugger. Keep Visual Studio updated to at least 2022, and disable "Enable Native Debugging" unless you absolutely need it. For production deployments, if you see this error in an event log but the app runs fine, ignore it. It's a debugging artifact, not a real problem.

Related Errors in Programming & Dev Tools
0XC0000009 STATUS_BAD_INITIAL_STACK (0XC0000009) Fix in Windows Threads 0X00003702 Fix ERROR_SXS_CORRUPT_ACTIVATION_STACK (0X00003702) 0XC00000FD Fix Stack Overflow 0XC00000FD: Guard Page Error in 2 Steps java.lang.OutOfMemoryError: Java heap space Fix Java OutOfMemoryError: Java heap space

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.