170

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?

G S
  • 35,511
  • 22
  • 84
  • 118
  • 90
    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. – Hans Passant Jun 06 '13 at 08:16

3 Answers3

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.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 4
    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. – surfen Jul 13 '12 at 11:12
  • That's very unlikely to be relevant, the C++ IDE doesn't use a hosting process nor is it used in design mode. – Hans Passant Dec 04 '12 at 02:20
  • 2
    Also, on the Microsoft web site (http://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. – Jay Imerman Sep 24 '13 at 15:26
  • 6
    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. – gpvos Jun 14 '16 at 15:03
  • 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. – RBT Apr 05 '17 at 09:24
  • 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. – Jeremy Cowles Sep 14 '18 at 17:41
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

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
6

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

ChrisW
  • 54,973
  • 13
  • 116
  • 224
Eric Dahlvang
  • 8,252
  • 4
  • 29
  • 50
  • 1
    And a few details are described at http://msdn.microsoft.com/en-us/library/ms185331.aspx – vines May 19 '14 at 23:01