Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to force an "Any CPU" compiled app to run in 32bit mode on 64bit OS?

If I have a "Any CPU" compiled .NET app, it will run in 64bit mode on a 64bit OS.

But if I, for whatever reason, wants to force this app to run in 32bit mode. (As if it were compiled using "x86"). Recompiling is not an option, so is this possible to config at run time ? With the .manifest file perhaps?

like image 200
Magnus Johansson Avatar asked Jun 12 '09 08:06

Magnus Johansson


1 Answers

I got a new solution!

Writing a custom .NET host is a better solution for this question. Because host is native applications, if you compile it as 32/64bit app, the assembly it loads will run on 32/64bit mode.

Don't need to worry about hosting because .NET build processes provide a default host to run .NET applications. In some specialized circumstances, though, it can be useful to explicitly host the .NET runtime.

So, you can prepare two host (C++ app), one build as 32bit app, the other is 64bit. And make a launch (exe or script) that invoke the host which mode you like. The host will load and run your assembly with the same mode as the host.

There is a tutoral about Hosting Core CLR: Write a custom .NET Core host to control the .NET runtime from your native code.

If your assembly is .net framework app, see Hosting the CLR the Right Way.

like image 70
anchur Avatar answered Sep 20 '22 09:09

anchur