Force .NET application to run in 32-bit process on 64-bit Windows

64-bit Windows has been around for a number of years, but there are a number of quirks that make it more difficult to work with than 32-bit Windows.  At my day job, I’m developing C# software on 64-bit Windows 7 using Visual Studio 2008 and I have to use some 32-bit DLLs provided by a third party.  We wrote some code to wrap these DLLs in C++, and I needed to debug into those wrappers.  When I tried to set a breakpoint in the C++ source code, instead of getting a filled in circle on the line indicating that the breakpoint will be hit, an empty circle with a yellow triangle in the corner is displayed.  Hovering over the icon displays a message indicating where the breakpoint is set and some text at the bottom explaining why the yellow triangle is being displayed:

The breakpoint will not currently be hit. No symbols have been loaded for this document.

Clearly this was due to trying to load a 32-bit DLL in a 64-bit process.  So the question is, how do you force a .NET application to run in a 32-bit process on 64-bit Windows?  Gabriel Schenker does a very nice job of describing the various ways of doing this.  I’ll summarize them here.

Set the platform target

When building a managed application in Visual Studio, you can specify the target platform to be either x86 or x64.

Visual Studio Platform Target x86

Setting this to x86 will force the target assembly (.dll or .exe) to be built as a 32-bit application, but if the assembly that loads the target assembly is running in a 64-bit process, it will fail to load your assembly.  Therefore, you need to make sure that if your application needs to load a 32-bit DLL that it is running in a 32-bit process.

Note that it is not required that you specify x86 to allow your assembly to be loaded in a 32-bit process.  If you specify Any CPU it can be loaded in either a 32-bit or a 64-bit process.

Force IIS to create a 32-bit app pool worker process

If your application is running as a web app, meaning it is running in an IIS app pool worker process, you’ll want that worker process (w3wp.exe) to be a 32-bit process.  That can be specified in the advanced settings of the app pool:

  1. Select the app pool for your web app.
  2. Click Advanced Settings… under Edit Application Pool on the right.
  3. Change the value of Enable 32-Bit Applications under (General) to True.

IIS Advanced Settings Enable 32-Bit Applications

Note that the word “Enable” in the setting doesn’t mean “allow” as in “allow either 32- or 64-bit applications.”  It actually means “force” as in “force the worker process to run in 32-bit mode so that 32-bit applications are supported.”  This means that the app pool worker process will always be launched as a 32-bit process when this setting has a value of True.  Setting it to False will launch a 64-bit app pool worker process.

Note that when an app pool worker process is started, it shows up in the Image Name column on the Processes tab in Task Manager as w3wp.exe.  When the Enable 32-Bit Applications setting has a value of True, it will be listed as w3wp.exe *32.

Modify the 32-bit flag in the assembly

This solution is intended for use by those that are not able to modify the build options.  The assembly header has a number of flags including one called 32BIT.  The CorFlags conversion tool allows you to modify the values of various flags, including the 32BIT flag.  You can use the following command to force the assembly to require a 32-bit process:

CorFlags MyAssembly.exe /32BIT+

The following command will clear the flag:

CorFlags MyAssembly.exe /32BIT-

Create a wrapper application

This solution allows you to make sure that you are running an application in a process with of a particular “bitness.”  Gabriel has a really good solution to this with source code in his post.

Additional Note

In my current position I end up having to attach to an existing w3wp.exe process to debug the web service.  Some of the web services are managed and some are managed/native.  Don’t forget to change the Attach to settings to include both Managed code and Native code.  However, this will only work when attaching to 32-bit processes.  Attempting to attach to a 64-bit process in this way will treat you to the following message:

Unable to attach to the process. Mixed mode debugging is not supported on Windows 64-bit platforms.

Resources

13 Responses to “Force .NET application to run in 32-bit process on 64-bit Windows on “Force .NET application to run in 32-bit process on 64-bit Windows”

  • [...] de un poco de investigación, encontré este enlace describiendo las distintas posibilidades que tenemos. Voy a explicar cuál es la que aplicaba a mi [...]

  • I can successfuly used the 32bit dll by creating a wrapper that uses x86 as platform target in 64 bit machine that uses windows server 2008 but when this wrapper was created as web service, the dll is not working.

    I already tried using the iis worker process that enables 32 bit and used the target platform as x86 for my webservice but it is still not working..

  • I have been seeing some info about this topic trough internet… and I ain’t see such windows “Set the platform target” as you show in your tutorial… I’m using vs2010… and the only options I have in my dropdown ins x64 and Itanium….. no x86 or any cpu…
    witch version do you use….
    if I can do it works… will be very helpfull…

    regards!

  • Hi Dave

    I hope that you can help me please.The “enable 32-bit applications TRUE” is not visible in my menu how do I turn it on? Thank you fr your time.

    Regards.

    Pieter

  • Hi,
    This post has been written some time ago but I try my question. I am in the same situation as yours but but passing from XP x86 to win7 x64. My application is mainly calculations (not to heavy) I noticed a slowing down of my application, any idea why? Problem of process priority? because I don’t reach the limit of the memory?
    application c# in vs 2008 running on Win7 pro with dual core 2.4G 2GRam

  • Dear Sir,
    I want ask one question related to .net application.
    suppose I have created a C#.net application and then created .exe file for the client. When we want run that application file on the client’s computer system, we have to install Visual Studio on that System.
    My Question is: Is there no any process or method, by using which client can run program without installing Visual Studio?

  • @gregory: Anytime you run an application that was designed for one processor architecture on a machine with another processor architecture, you’re going to see a performance hit. That includes running a 32-bit application on a 64-bit operating system.

  • @Rudra Pratap Singh: The only thing that should be required to run a .NET application on another machine is that the proper version of .NET is installed. You shouldn’t have to install Visual Studio on that machine. Just distribute the assembly (.exe) file and you should be good. If that doesn’t do it for you, what type of problems are you running into?

  • [...] Force .NET application to run in 32-bit process on 64-bit Windows Like this:喜歡Be the first to like this. 發表在 電腦和網際網路 中 | Tagged Windows Media Rights Manager、WMRM、x64 [...]

  • it helped me to solve the similar issue. thank you

  • Hello David Sir,
    I am finding a similar problem . My C# app copies the 4 GB content to drive C from F. I have achieved this task by using asynchronous, File Streams, multi-threading The C# app is developed on windows xp 32 bit OS . It works excellent on windows XP . But when i install the app on Windows 7 and Windows 8, the copy content action slows down too much as compared to Windows xp.

    So What is the solution for this? Plz help me…

  • Thank you,

    One of my client has issue with oledb driver, which does not work with 64 bit application, they told me to rewrite windows service, but thanks to corflags and your turotial, I solved the issue. Manay many thanks.

  • Thank u so much sir………x86 solve my problem..

Leave your comment...

Name (required)
Email (required)
Website