Export (0) Print
Expand All
5 out of 10 rated this helpful - Rate this topic

Hosting Overview

.NET Framework applications automatically host the common language runtime that they were built against. If you compile your managed code as an .exe assembly, the runtime is started automatically by mscoree.dll when the .exe is run. Unmanaged applications can also benefit from hosting the common language runtime. The runtime provides a framework for extending applications such as Internet Information Services (IIS) and SQL Server 2005.

Whether it is invoked automatically, as with managed .exe assemblies, or loaded by using the unmanaged hosting API, a .NET Framework application requires a piece of code called a runtime host. The runtime host loads the runtime into a process, creates application domains within the process, and loads and executes user code within those application domains.

The .NET Framework version 2.0 enables applications that host the CLR to control many features of the runtime. You can replace some features, such as memory allocation and assembly loading, with custom implementations. You can control the behavior of other features, receive notifications of events in the runtime, and manage application domains.

The .NET Framework 4 consolidates many of the version 2.0 hosting APIs. In addition, .NET Framework 4 supports in-process side-by-side runtime host activation, and provides other enhancements.

This overview contains the following sections:

The .NET Framework 4 hosting API provides the CLRCreateInstance function, which can return the ICLRMetaHost interface. You can then call the GetRuntime method on this interface to get a specific ICLRRuntimeInfo interface, given a particular CLR version. This procedure supersedes the CorBindToRuntimeEx method that is used by the .NET Framework 2.0 hosting API.

The .NET Framework version 2.0 hosting API provides the CorBindToRuntimeEx function to initialize the runtime. You can choose which version of the runtime to load, but a process can host only one version. If version 2.0, 3.0, or 3.5 is loaded, the function returns the ICLRRuntimeHost interface, which is used to start the runtime and execute managed code.

The .NET Framework version 1 hosting API provides the ICorRuntimeHost interface.

Starting the runtime is discussed in Loading the Common Language Runtime into a Process, and executing managed code is discussed in Transitioning to Managed Hosting Code.

Back to top

In the .NET Framework 2.0, the CLR provides hosting management interfaces to control many features of the hosted runtime, enables the host application to implement other management interfaces provided by the runtime, and lets you implement your own hosting management interfaces.

For purposes of discovery, the management interfaces fall into two broad categories:

  • Management interfaces that the host implements and the runtime discovers through the IHostControl interface.

  • Management interfaces that the CLR provides and the host discovers through the ICLRControl interface.

The following table groups the interfaces by the kind of functionality they provide. The most important interface within each group is listed first.

Group

Function

Interfaces

Assembly loading management

Enables the host to customize the locations from which assemblies are loaded, the way versions are managed, and the formats from which assemblies can be loaded. For example, assemblies could be loaded from a database instead of from files on the hard disk.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostAssemblyManager

IHostAssemblyStore

ICLRAssemblyReferenceList

ICLRAssemblyIdentityManager

Policy management

Enables the host to specify the way program failures are handled, to support different reliability requirements.

The host uses the ICLRControl interface to gain access to the runtime manager, and implements IHostPolicyManager callbacks for failure notifications from the runtime.

ICLRPolicyManager

IHostPolicyManager

Host protection management

Enables the host to enforce its own programming model, by preventing the use of specified types or members. For example, the host can disallow the use of threading or synchronization primitives.

The host uses the ICLRControl interface to gain access to the runtime manager.

ICLRHostProtectionManager

Memory management

Enables the host to control memory allocation by providing replacements for the operating system functions that the CLR uses to allocate memory.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostMemoryManager

IHostMAlloc

ICLRMemoryNotificationCallback

Garbage collection management

Enables the host to implement methods to receive notification of the beginning and end of garbage collection. Enables the host to initiate collections, to collect statistics, and to specify some characteristics of collection.

The host uses the ICLRControl interface to gain access to the runtime manager. The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostGCManager

ICLRGCManager

Debug management

Enables the host to discover whether a debugger is attached, to provide additional debugging information, and to customize debugging tasks.

The host uses the ICLRControl interface to gain access to the runtime manager.

ICLRDebugManager

CLR event management

Enables a host to register for notification of the events enumerated by EClrEvent.

The host uses the ICLRControl interface to gain access to the runtime manager, and implements its event handlers by using the IActionOnCLREvent interface.

ICLROnEventManager

IActionOnCLREvent

Task management

Enables the host to be notified whenever a thread makes a transition between managed and unmanaged code. Enables the host to control thread affinity, when tasks are started and stopped, and how they are scheduled.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostTaskManager

ICLRTaskManager

IHostTask

ICLRTask

Thread pool management

Enables the host to implement its own thread pool for the runtime to use.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostThreadPoolManager

Synchronization management

Enables the host to implement its own synchronization primitives for the runtime to use. The host can provide events, critical sections, and semaphores.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostSyncManager

ICLRSyncManager

IHostCrst

IHostManualEvent

IHostAutoEvent

IHostSemaphore

I/O completion management

Enables the host to implement its own implementation of asynchronous input/output.

The CLR uses the IHostControl interface to discover whether a host implements this group of interfaces.

IHostIoCompletionManager

Note Note

The hosting interfaces for earlier versions of the runtime are documented in Deprecated CLR Hosting Interfaces and Coclasses.

Back to top

The .NET Framework 4 consolidates the 2.0 hosting API within the following interfaces:

  • ICLRMetaHost provides methods that return a specific version of the CLR, list all installed CLRs, list all in-process runtimes, return the activation interface, and discover the CLR version used to compile an assembly.

  • ICLRMetaHostPolicy supplies the GetRequestedRuntime method that provides a CLR interface based on a policy criteria, managed assembly, version and configuration file.

  • ICLRRuntimeInfo provides methods that return information about a specific runtime, including version, directory, and load status.

  • ICLRStrongName groups all CLR version 2.0 strong naming global static functions that are exported by MSCorEE.dll (except StrongNameErrorInfo) into a single interface. All ICLRStrongName methods return standard COM HRESULTS.

These interfaces encapsulate and supersede the .NET Framework 2.0 hosting interfaces.

Back to top

For programs that host the common language runtime, application domains provide greater reliability by isolating assemblies from one another. Assemblies can be unloaded from the process by unloading application domains.

To manage multiple application domains, the .NET Framework provides the AppDomainManager class as a base class from which you can derive your own application domain managers. The application domain manager you design for your host application is essentially an extension of the host, in managed code. It is automatically loaded into each application domain created in your process.

The application domain manager can improve performance by eliminating some transitions between managed and unmanaged code. It can receive notification of the creation of new application domains, and give you an opportunity to configure them. The application domain manager also provides a way for an unmanaged host to call managed code.

Back to top

Title

Description

Loading the Common Language Runtime into a Process

Describes how to load the runtime into a process, initialize it, and set values to specify its behavior.

Unloading Domains and Shutting Down a Process

Describes how to unload application domains and shut down a process.

Setting Role-Based Security Policy and Principals

Describes how to set a role-based security policy.

Setting Application Domain-Level Security Policy

Describes how to set an application domain-level security policy.

Loading and Executing User Code

Describes how to load and execute user code.

Creating and Configuring Application Domains

Describes how to create and configure application domains in which to run user code.

Determining Application Domain Boundaries

Describes how to determine where to set boundaries for a new application domain.

Transitioning to Managed Hosting Code

Describes how to make the transition from unmanaged code to execute managed hosting code and user code.

Activation Configuration Files

Describes how to activate a version of the runtime other than the one specified in the application configuration file.

Runtime Hosts

Describes hosts that ship with the .NET Framework.

Application Domains

Describes the constructs that hosts use to isolate code running within a process.

Side-by-Side Execution in the .NET Framework

Describes running multiple versions of an application, a component, or the runtime.

CLR Hosting Interfaces Added in the .NET Framework 4 and 4.5

Describes the unmanaged interfaces for hosting the runtime in the .NET Framework version 4.

CLR Hosting Interfaces

Describes the unmanaged interfaces for hosting the runtime in the .NET Framework version 2.0.

Back to top

Show:
© 2014 Microsoft. All rights reserved.