Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Introducing Slide Speaker: Videos with Voice-over from your PowerPoint and Google Slides Presentations

Call to Console.WriteLine() crashes Visual Studio 2010 Load Test Agent


This doesn’t make a shred of sense to me but I’ve been working on running some MSTest unit tests as part of a Visual Studio 2010 Load Test on a VS2010 Load Test Rig and ran into a very weird problem. 

Most of the unit tests behave perfectly when run as part of a load test but one kept causing problems.  When I’d run the load test I’d get an exception message saying “Error occurred running test.  Could not run load test ‘{load test name}’ on agent ‘{agent name}’: The given key was not present in dictionary.

SNAGHTMLf13a0a1

I’d get this exception message box a few times at the start of the load test and then the load test would abort.  So a load test that should take 3 minutes was aborting after maybe 15 seconds.

SNAGHTMLf161218

Basically, what was happening is that *something* in this unit test was causing the QTAgent32.exe process to crash. 

When I’d look at the event log on the load test agent machine, I’d see a couple of different errors in the Application Log:

1. QTAgentService.exe logging an error saying “OutOfProcessStrategy.ProcessMonitorThread: Agent process was shut down unexpectedly; will attempt to restart”

2. QTAgent32.exe logging an error saying “The process was terminated due to stack overflow.”

Error Message #1

Log Name:      Application
Source:        VSTTAgent
Date:          4/12/2012 1:43:48 PM
Event ID:      0
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      WSPCTESTMAC13
Description:
(QTAgentService.exe, PID 2844, Thread 16) OutOfProcessStrategy.ProcessMonitorThread: Agent process was shut down unexpectedly; will attempt to restart
Event Xml:
<Event xmlns=”http://schemas.microsoft.com/win/2004/08/events/event”>
  <System>
    <Provider Name=”VSTTAgent” />
    <EventID Qualifiers=”0″>0</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime=”2012-04-12T17:43:48.000Z” />
    <EventRecordID>70373</EventRecordID>
    <Channel>Application</Channel>
    <Computer>WSPCTESTMAC13</Computer>
    <Security />
  </System>
  <EventData>
    <Data>(QTAgentService.exe, PID 2844, Thread 16) OutOfProcessStrategy.ProcessMonitorThread: Agent process was shut down unexpectedly; will attempt to restart</Data>
  </EventData>
</Event>

Error Message #2

Log Name:      Application
Source:        .NET Runtime
Date:          4/12/2012 1:43:48 PM
Event ID:      1027
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      WSPCTESTMAC13
Description:
Application: QTAgent32.exe
Framework Version: v4.0.30319
Description: The process was terminated due to stack overflow.

Event Xml:
<Event xmlns=”http://schemas.microsoft.com/win/2004/08/events/event”>
  <System>
    <Provider Name=”.NET Runtime” />
    <EventID Qualifiers=”0″>1027</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime=”2012-04-12T17:43:48.000Z” />
    <EventRecordID>70372</EventRecordID>
    <Channel>Application</Channel>
    <Computer>WSPCTESTMAC13</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application: QTAgent32.exe
Framework Version: v4.0.30319
Description: The process was terminated due to stack overflow.
</Data>
  </EventData>
</Event>

The Cause of the Problem

The unit tests that I was working on are making lots of WCF calls so at first, I spent a lot of time trying to diagnose possible problems with WCF.  The tests would execute just fine when they weren’t running as part of a load test and I ran them directly from the MSTest runner.  So, I was fairly confident that it wasn’t a problem with the logic. 

Next, I started commenting out portions of the unit test so that I could see exactly where it was dying.  I don’t know how this is possible but I tracked the problem down to a Console.WriteLine() statement.  The flow of the code went something like this:

DoWcfServiceOperation1();
DoWcfServiceOperation2();
Console.WriteLine(); // BOOOM!!!!
DoWcfServiceOperation3();

Here’s the actual Console.WriteLine() that was causing the problem.

SNAGHTML1a08406

Unless I’m missing something, it’s a perfectly ordinary and correct Console.WriteLine() statement. When it’s there, the load test and the load test rig crashes. When it’s not there, everything works great.

I’m stumped.

So, I hope this helps someone out and if any of you have any clue why this would be happening, let me know.

-Ben

 

— Having trouble with Visual Studio 2010 or Visual Studio 2012 Load Tests?  Want to know more about the new Visual Studio 2012 Load Test Project?  Need someone to see if your app can handle the pressure?  Drop us a line at info@benday.com.

SUBSCRIBE TO THE BLOG


3 responses to “Call to Console.WriteLine() crashes Visual Studio 2010 Load Test Agent”

  1. James Davis Avatar
    James Davis

    Not sure if you’ve tried to debug to load test and catch the exception.

    1. Ben Day Avatar

      Hi James,

      The stack traces that are in the blog post are the ones that come flying out. If I were to guess, the testing framework does some kind of Console.Out redirection and that’s where those exceptions come from. That’s just a guess though.

      -Ben

  2. Sam Woods Avatar
    Sam Woods

    THANK YOU! This definitely did help. I was getting this error after adding a listener and using Trace.Writeline. After removing the listener, I was finally able to get my tests running again. Horrible bug, horrible error message.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.