Search

Unit Tests Which Show Windows Cause VsTestHost/MsTest ShutDown Crashes in VS 2008 RTM by scottj1s

Closed
as Fixed Help for as Fixed

1
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 318333
Opened: 12/17/2007 4:17:58 PM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
I have a project with several unit tests that require windows/dialogs to be displayed in order to exercise my WPF-based classes. Until VS 2008 RTM (i.e., with Beta 1 and Beta 2), these tests all passed successfully. In VS 2008 RTM, the test host (whether VsTestHost or MsTest) both crash on shutdown, with the exception message: "COM object that has been separated from its underlying RCW cannot be used." This is a blocking issue in that the test host also returns a non-zero exit code, causing failed automated builds (even though all the tests in fact pass). The only solution we've found is to remove the failing tests.

Note: A similar problem was reported earlier with VS 2005, under ID 97820.
Details (expand)
Product Language
English

Version

Visual Studio 2008 (All Products and Editions)
Operating System
Windows Vista
Operating System Language
English
Steps to Reproduce
Create a test method that simply shows a window, such as:

[TestMethod]
public void Test()
{
Window window = new Window();
window.Show();
window.Close();
window = null;
}

Please see attachments for additional info. Test project represents minimal steps need to repro in our organization - an empty C# console app with a single test case that creates and shows a WPF Window.
Actual Results
Test host terminates with the following exception message, one per Window.Show call:
"COM object that has been separated from its underlying RCW cannot be used."

Exit code also ends up being non-zero, failing automated builds.
Expected Results
Either:
1. The com/rcw wiring invoked by Window.Show should be properly cleaned up in the test host shutdown logic, to prevent crashes, or
2. Crashes during test host shutdown should not interfere with the propagation of test method results to the exit code (should not fail the build).
TAP Code (if applicable)
 
      You can indicate your satisfaction with how Microsoft handled this issue by completing this quick 3 question survey. [Details]

 

File Attachments
2 attachments
318333.jpg
mstest.zip
Sign in to post a comment.
Posted by Microsoft on 12/18/2007 at 1:56 AM
Thanks for reporting the issue.
In order to fix the issue, we must first reproduce the issue in our labs. We are unable to reproduce the issue with the steps you provided.
It may help if you provide us with:

1. more exact steps to repro the issue
2. more snapshots.

If we do not receive a response from you after 7-days , we will automatically close your issue. There is no obligation to respond -- at any time you may edit your issue via Connect and change the status to “Active.”

Thank you,
Visual Studio Product Team
Posted by scottj1s on 12/18/2007 at 10:58 AM
Please see attachments for additional info. Test project represents minimal steps need to repro in our organization - an empty C# console app with a single test case that creates and shows a WPF Window. JPG shows results of running the single test case from within the IDE.
Posted by Microsoft on 12/19/2007 at 12:45 AM
Thanks for your response. We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 1/10/2008 at 2:26 PM
Thank you for providing a repro for this issue. Can you please try implementing the following work around: in your test class, add the following cleanup method (or add this code to an existing cleanup method):

        [TestCleanup]
        public void CleanUp()
        {
            System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown();
        }


Thank you,
Visual Studio Product Team
Posted by scottj1s on 1/10/2008 at 3:24 PM
Yes, adding the TestCleanup call did the trick. Thank you!
Posted by aniketT on 6/26/2008 at 1:26 AM
Hi

Posted by aniketT on 6/26/2008 at 1:28 AM
Hi I'm too facing the same issue just difference here is that I'm using NUnit ! but if I use the workaround above then the next test case starts failing and complaining dispatcher is not started !!!!!! Any solution on this ?