.netclrclr-hosting

What is CLR hosting?


What is CLR hosting? What is the use case for that?


Solution

  • See here for information about CLR hosting that was relevant for CLR v2 (.NET 2.0, 3.0 and 3.5). For information about the newer CLR Hosting API in .NET 4.0, see here.

    Basically, the CLR acts as a library that can be loaded and "hosted" by a process. You can develop an app that loads and hosts the CLR if you wish; that would allow your app to contain a whole CLR virtual machine, load assemblies and run .NET managed code all within it.

    SQL Server 2008, for example, can do this. You can write .NET code that is stored in a SQL Server database and run from within the SQL Server database engine. SQL Server is hosting the CLR to achieve that.

    A CLR host other than the Windows shell (the usual user interface) can provide a specific context for your code to run. This can be useful for specialised applications or very particular scenarios. MSDN (link above) has some guidelines on these matters.