vstesthost.exe opening a dialog box when background thread raises exception

The app I am testing is raising an exception in a background thread after the test class is already destroyed. This is causing VSTestHost.exe to open a dialog box (below) and subsequently exit.

=-=-=-=-=-

VSTestHost.exe has encountered a problem and needs to close. Sorry for the inconvenience

Debug | Close

=-=-=-=-=-

I read in a separate thread that the way to prevent VSTestHost from exiting when it captures an unhandled exception is to put the following line in the VSTestHost.exe.config file: <legacyUnhandledExceptionPolicy enabled="1"/>

related thread: Exceptions in unit tests in secondary threads kills vstesthost http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=92232&SiteID=1

I tried that setting but it does not seem to make a difference in whether or not that dialog box comes up. I actually don't care about VSTestHost getting killed so much as the fact that the dialog box is hampering my ability to run these tests unattended as part of our automated build process.

The dialog box i'm referring to is actually owned by dw20.exe and I found another article on the MS Support site on how to disable this app: here http://support.microsoft.com/default.aspx scid=kb%3Ben-us%3B841477



Answer this question

vstesthost.exe opening a dialog box when background thread raises exception

  • aak165842

    There some exception in .NET that cannot be caught by try-catch or ignored by <legacyUnhandledExceptionPolicy enabled="1"/>. For instance if you call a function recursively you will get StackOverflowException which whatever you do will cause the program to terminate, no matter if this is on background thread or not. here's an example of code that will terminate the app even if you do <legacyUnhandledExceptionPolicy enabled="1"/>.

    try
    {
    ThreadFunc();
    }
    catch {}

    private void ThreadFunc()
    {
    ThreadFunc();
    }

    Can you provide more details what kind of exception and under what conditions your "code under test" application throws

    Thank you,
    Michael Koltachev
    VS Team Test


  • Chernichkin Stanislav

    This turned out to be pilot error...a typo in the app.config file. Sorry for the noise :(
  • vstesthost.exe opening a dialog box when background thread raises exception