What is the purpose of the Visual Studio Hosting Process?
Asked Answered
K

3

171

When debugging a program using Visual Studio you are given the option to Enable the Visual Studio hosting process. What is this purpose of this option and what effect does it have?

Kinna answered 15/1, 2010 at 6:49 Comment(1)
Hard to believe this question was closed as "not a real question"! The hosting process is real enough, knowing what it does is important to any .NET programmer. As is any mysterious option in a Visual Studio setting page that is easy to get to. Let's get this re-opened folks.Cysto
C
90

The MSDN library doesn't give very good info on the "hosting process". The last two features listed in Eric's link are actually problems induced by the feature. There's another one that you're bound to run into sooner or later: it uses a different app.config file. The active one is named yourapp.vshost.exe.config. Watch out for this when you make manual changes to the file.

Another feature it supports that's very visible when you debug your app but isn't mentioned anywhere is what happens to the output produced by Console.Write(). In a non-console mode app, it gets redirected to the IDE's Output window. Very useful.

The term "hosting" refers to a feature of the CLR, it can be "hosted". Examples of custom CLR hosts are SQL Server and ASP.NET. Hosting allows one to configure the CLR before it gets started. One primary use of this is configuring the primary AppDomain and setting up custom security policies. Which is exactly what the hosting process is doing.

A good example of a custom CLR host is available in this question.

Long story short: in debug mode you are running with a customized version of the CLR, one that improves the debugging experience.

Cysto answered 15/1, 2010 at 9:28 Comment(6)
I have a habit of disabling this feature on every new project. I've run into strange issues when working with C++/CLI WinForms Designer, that didn't occur with this feature disabled.Jubilant
That's very unlikely to be relevant, the C++ IDE doesn't use a hosting process nor is it used in design mode.Cysto
Also, on the Microsoft web site (msdn.microsoft.com/en-us/library/ms242202.aspx) it states that it enables Partial Trust Debugging (no clue what that is), and Design Time Expression Evaluation, which I use often to evaluate expressions in the Immediate window. However, hosting does have its issues as noted.Conventual
The hosting process tends to keep DLLs loaded that I want to write to from another running copy of Visual Studio. Killing the hosting process, or even exiting and restarting the offending VS, does not help, because the newly started hosting process loads the DLL again. This is the reason why I usually disable it.Thy
I'm observing that the Console.WriteLine logs get printed in output window even when I disable the Enable the Visual Studio hosting process option from properties window of a windows forms project. Not sure why.Avicenna
I'm also seeing strange behavior where the hosting process seems to be loading an outdated version of a C++ DLL which I'm compiling and then testing with a C# executable.Straiten
D
17

From MSDN:

The Visual Studio hosting process improves debugger performance and enables new debugger features, such as partial-trust debugging and design-time expression evaluation

Danseur answered 15/1, 2010 at 6:52 Comment(0)
A
6

It's explained here in MSDN: Debugging and the Hosting Process.

Arterialize answered 15/1, 2010 at 6:51 Comment(1)
And a few details are described at msdn.microsoft.com/en-us/library/ms185331.aspxHighpitched

© 2022 - 2024 — McMap. All rights reserved.