34

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

0

3 Answers 3

29

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.

4
  • 2
    +1 Thanks for the answer. Also: when a .NET executable is double-clicked and launched, who hosts the CLR? Is it hosted by Windows Explorer?
    – Sabuncu
    Aug 6, 2013 at 18:46
  • 1
    @Sabuncu: Yes. That is the Windows shell I was mentioning in my answer.
    – CesarGon
    Aug 6, 2013 at 21:31
  • Thanks. I saw your "Windows shell" reference, but wasn't sure. In this case, I think you are using "shell" in the generic sense, not a shell program such as the DOS cmd.exe or the PowerShell console.
    – Sabuncu
    Aug 7, 2013 at 7:21
  • 2
    Well, "Windows shell" is a well known phrase to refer to the user interface components of the Windows OS from the development perspective. Please see here: msdn.microsoft.com/en-us/library/windows/desktop/… It is also the phrase used by .NET CLR documentation to discuss hosting alternatives.
    – CesarGon
    Aug 7, 2013 at 8:41
12

CLR Hosting is Hosting the .NET Common Language Runtime in a process of your choice.

The use case would be situations where existing environments don't suit your requirements. Some of the existing environments are ASP.NET, WinForms, Windows Workflow Foundation, etc. If these don't suit your requirements, you can host it yourself.

2

CLR Hosting is Hosting uses .NEt application.When you start the .NET runtime inside a native process, that native application becomes a host for the runtime. This lets you add .NET capabilities to your native applications.

If the runtime is running, but it hasn't got any loaded user code yet. Some internal thread scheduler and garbage collector are surely running, because they are part of the CLR runtime It is very complicated than other hosting services.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.