Loading the Common Language Runtime into a Process

Before any managed code can be executed, the host must load and initialize the common language runtime. All hosts start with an unmanaged stub because the runtime is not yet running in the process. The .NET Framework provides a set of unmanaged APIs called the hosting APIs that the host can use to start the runtime. For more information, see Hosting Interfaces.

To load the runtime into a process, a host calls the CorBindToRuntimeEx Function function. The prototype for CorBindToRuntimeEx Function is located in Mscoree.h in the Include directory of the Windows Software Development Kit (SDK). The host uses CorBindToRuntimeEx Function to control which version of the runtime to load and the behavior of basic functions such as garbage collection and assembly loading. A host can set the values listed in the following table.

Value

Description

Concurrent garbage collection

Specifies whether garbage collection is done on background threads or on the threads that run user code.

Loader optimization

Controls whether assemblies are loaded in a domain-neutral manner. Loading assemblies in a domain-neutral manner enables JIT-compiled assembly code and read-only runtime data structures to be shared among all application domains within a process.

For more information, see Application Domains and Assemblies.

Server vs. workstation

Specifies whether to load the workstation build ("wks") or the server build ("svr") of the runtime.

Version

Specifies which version of the runtime to load into the process. To load version 1.0, use "v1.0.3705". To load version 1.1, use "v1.1.4322". To load version 2.0, use "v2.0.50727". A process can load only one version of the runtime.

For more information, see Side-by-side Execution

CorBindToRuntimeEx Function takes three additional parameters: the CLSID of the object that contains the ICLRRuntimeHost Interface interface, CLSID_CLRRuntimeHost; the IID of the interface, IID_ICLRRuntimeHost; and an [out] parameter that receives the ICLRRuntimeHost Interface pointer.

Note

For versions 1.0 and 1.1, use CLSID_CorRuntimeHost and IID_ICorRuntimeHost to obtain the ICorRuntimeHost Interface interface.

Use ICLRRuntimeHost Interface to start the runtime, to execute managed code, to obtain a pointer to the ICLRControl Interface interface that provides access to the managers implemented by the common language runtime, and to register a host control object that implements the IHostControl Interface interface. The common language runtime calls IHostControl Interface to determine what managers the host implements.

See Also

Concepts

Transitioning to Managed Hosting Code

Reference

AppDomainSetup

CorBindToRuntimeEx Function

ICLRRuntimeHost Interface

ICLRControl Interface

Other Resources

Hosting the Common Language Runtime