Programmatically specify which version of .NET to load
My application is a native, non-.NET application. However, at times it may need to invoke some .NET services through COM. Sometimes it needs to load a specific version of .NET to accomplish what it needs to do. (My app uses a COM interface to System.EnterpriseServices in order to programmatically register assemblies and install them in the GAC).
Normally, I could use MyApp.exe.config (as explained here) if this information was known ahead of time and didn't change between runs.
Unfortunately, the specific version of .NET to load will not be known until runtime (and in fact, may change between runs on the same system). Therefore using MyApp.exe.config will not work.
Is there a way for a native application to supply this information to Windows programmatically before it loads .NET?
(Though my application is written in Delphi, this is more of a general Windows question and answers in any language would be welcome)
You will have to write your own CLR host, instead of relying on the IJW "it just works" .NET feature.
If .NET 4 is installed on the machine, this link describes how to do it: Loading the Common Language Runtime into a Process. With .NET 4, you can even load multiple versions of the CLR side by side in the same process (with restrictions though).
Additional information: Use CLR4 Hosting API to invoke .NET assembly from native C++