Compartilhar via


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. The prototype for CorBindToRuntimeEx is located in Mscoree.h in the Include directory of the .NET Framework SDK. The host uses CorBindToRuntimeEx 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 takes three additional parameters: the CLSID of the object that contains the ICLRRuntimeHost interface, CLSID_CLRRuntimeHost; the IID of the interface, IID_ICLRRuntimeHost; and an [out] parameter that receives the ICLRRuntimeHost pointer.

NoteNote

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

Use ICLRRuntimeHost to start the runtime, to execute managed code, to obtain a pointer to the ICLRControl 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. The common language runtime calls IHostControl to determine what managers the host implements.

See Also

Reference

AppDomainSetup Class
CorBindToRuntimeEx
ICLRRuntimeHost
ICLRControl

Concepts

Transitioning to Managed Hosting Code

Other Resources

Hosting the Common Language Runtime