AppDomain.FriendlyName and vshost

In this post, Dave Templin explains the purpose of the .vshost.exe that gets created automatically by Visual Studio Whidbey. What it also mentions is the fact that the application domain my code runs in is of course different when I run in the debugger. I found a problem with this where the FriendlyName is concerned.

I’ve been using the FriendlyName to construct names based on my application’s exe name, the same way the normal app.config files work. The problem is, as soon as I run the app in the debugger, the FriendlyName is no longer the same and the config file that’s already there isn’t found. To solve this, I was looking for a way to find out the “real” base name of my application’s exe file, without the vshost. part. Apparently, there’s no special property or anything that would let me access this information directly… maybe that would be a useful extension to the System.Diagnostics.Debugger class.

The solution was simple for the moment: I used a regular expression to do a simple replacement on the string:

  string myName = Regex.Replace(AppDomain.CurrentDomain.FriendlyName, 
    @"(?<basename>.*).vshost(?<extension>\..*)", "${basename}${extension}");

Of course that’s not a perfect solution, but as it’s only relevant for a developer who may run the program in the debugger, it should be alright for now. Maybe they’ll expose some more information about this to the running app in the future so it can behave a bit more intelligently… or I’m missing something 🙂

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s