Mike Thompson
Mike Thompson

Reputation: 6738

Force a C# WinForms app built with AnyCPU to debug as a 32 bit process

I have a C# project build with AnyCPU. We also dynamically load a feature which currently relies on 32 bit native DLLs. With this feature switched off the application runs quite happily as a 64 bit application. Consequently, Visual Studio determines that the application will run in a 64 bit process. To force the application to run as a 32 bit process we have a Post Build step on the main project which uses CorFlags to set it 32 bit. This works fine when running the application outside of Visual Studio. However, if I debug the application by using F5 I get an error indicating that I have a 32/64 bit mismatch. It appears as though Visual Studio has determined that the application can run as a 64 bit process and sets up the debugger accordingly, unaware that I have run CorFlags to force it to 32 bit.

Is there any way to force Visual Studio to debug the application as a 32 bit process? I would like to leave the platform target as AnyCPU as the third party components will eventually be upgraded to 64 bit.

Upvotes: 0

Views: 540

Answers (1)

user817530
user817530

Reputation:

It's most likely Visual Studio's vshost of your application being built in a specific version and debugger can't figure it out, since the debugger has to be the same bit-flavor as the exe it's debugging (and all of it's assemblies).

You might try running the exe on it's own, and just attaching the process via the Debug menu. Might gain you better results for breakpoints, but without the vshost it won't be as verbose.

This is only a theory, and I currently do not have enough rep to comment your original thread; so if you find this incorrect, please disregard.

Upvotes: 0

Related Questions