Unit test AppDomain names and custom performance counters<P><FONT face="Verdana, Geneva, Arial, Sans-serif">I'm getting a really strange InvalidOperationException exception when trying to invoke a web service method from within a unit test.</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">The message from the exception is "Instance names used for writing to custom counters must be 127 characters or less."&nbsp; You can imagine my bewilderment at the message because I do not use custom counters in my unit test or in the web service.</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">Looking at the stack I see a call to System.Diagnostics.SharedPerformanceCounter's ctor.&nbsp; And to my surprise I see parameters like:</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">(string catName = ".net clr networking", string counterName = "connections established", string instanceName = "unittestadapterdomain_forc:_documents and settings_XXXXXX_my documents_visual studio 2005_projects_XXXXXXXXXXXXXXXXXXXX_testresults_XXXXXX_XXXXXXXXXXXX 2006-08-04 14_11_01_out_unittests.dll[4036]", System.Diagnostics.PerformanceCounterInstanceLifetime lifetime = Process)</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">[were sensitive data is replaced char-for-char by 'X']</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">Clearly using a path for the instanceName parameter is a really bad idea, given a path can contain up to 260 characters and a performance counter instance name is limited to 127 characters.</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">I get the impression this string is the name of the AppDomain for the unit test.&nbsp; Is there anything I can do to get around this?</FONT></P>© 2009 Microsoft Corporation. All rights reserved.Wed, 08 Oct 2008 22:45:33 Zc3160fc2-2fa6-49f1-b033-61cd099d1107http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#c3160fc2-2fa6-49f1-b033-61cd099d1107http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#c3160fc2-2fa6-49f1-b033-61cd099d1107Peter Ritchiehttp://social.msdn.microsoft.com/Profile/en-US/?user=Peter%20RitchieUnit test AppDomain names and custom performance counters<P><FONT face="Verdana, Geneva, Arial, Sans-serif">I'm getting a really strange InvalidOperationException exception when trying to invoke a web service method from within a unit test.</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">The message from the exception is "Instance names used for writing to custom counters must be 127 characters or less."&nbsp; You can imagine my bewilderment at the message because I do not use custom counters in my unit test or in the web service.</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">Looking at the stack I see a call to System.Diagnostics.SharedPerformanceCounter's ctor.&nbsp; And to my surprise I see parameters like:</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">(string catName = ".net clr networking", string counterName = "connections established", string instanceName = "unittestadapterdomain_forc:_documents and settings_XXXXXX_my documents_visual studio 2005_projects_XXXXXXXXXXXXXXXXXXXX_testresults_XXXXXX_XXXXXXXXXXXX 2006-08-04 14_11_01_out_unittests.dll[4036]", System.Diagnostics.PerformanceCounterInstanceLifetime lifetime = Process)</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">[were sensitive data is replaced char-for-char by 'X']</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">Clearly using a path for the instanceName parameter is a really bad idea, given a path can contain up to 260 characters and a performance counter instance name is limited to 127 characters.</FONT></P> <P><FONT face="Verdana, Geneva, Arial, Sans-serif">I get the impression this string is the name of the AppDomain for the unit test.&nbsp; Is there anything I can do to get around this?</FONT></P>Fri, 04 Aug 2006 18:38:14 Z2006-08-09T18:40:00Zhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#5473bd71-e6b4-4a08-816d-03b01527c16dhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#5473bd71-e6b4-4a08-816d-03b01527c16dBoris Vidolov MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Boris%20Vidolov%20MSFTUnit test AppDomain names and custom performance counters<p><span style="font-size:9.5pt;color:black">Hello Peter,</span></p> <p><span style="font-size:9.5pt;color:black">Yes, you are right - the name of the AppDomain is in the form above. We are currently changing the design around creation of the AppDomains for the next version of Visual Studio. The following steps will make that name shorter and could potentially fix the problem for you:</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span style="">1.<span style="font:7pt 'Times New Roman'">     </span></span></span><span style="font-size:9.5pt;color:black">Edit the test run configuration file in an XML editor and modify the following two fields:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt;line-height:normal"><span style="font-size:10pt;color:blue;font-family:'Courier New'"></span><font face=Calibri>&lt;</span></font><span style="font-size:10pt;color:#a31515;font-family:'Courier New'">userDeploymentRoot</span><span style="font-size:10pt;color:blue;font-family:'Courier New'"> </span><span style="font-size:10pt;color:red;font-family:'Courier New'">type</span><span style="font-size:10pt;color:blue;font-family:'Courier New'">=</span><span style="font-size:10pt;font-family:'Courier New'">&quot;<span style="color:blue">System.String</span>&quot;<span style="color:blue">&gt;</span><font style="background-color:#ffff00">c:\temp</font><span style="color:blue">&lt;/</span><span style="color:#a31515">userDeploymentRoot</span><span style="color:blue">&gt;</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt;line-height:normal"><span style="font-size:10pt;color:blue;font-family:'Courier New'">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:'Courier New'">useDefaultDeploymentRoot</span><span style="font-size:10pt;color:blue;font-family:'Courier New'"> </span><span style="font-size:10pt;color:red;font-family:'Courier New'">type</span><span style="font-size:10pt;color:blue;font-family:'Courier New'">=</span><span style="font-size:10pt;font-family:'Courier New'">&quot;<span style="color:blue">System.Boolean</span>&quot;<span style="color:blue">&gt; </span><font style="background-color:#ffff00">False</font><span style="color:blue">&lt;/</span><span style="color:#a31515">useDefaultDeploymentRoot</span><span style="color:blue">&gt;</span></span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span style="">2.<span style="font:7pt 'Times New Roman'">     </span></span></span><span style="font-size:9.5pt;color:black">Save the file and open it in the test run configuration editor</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span style="">3.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Go to “General” pane, set “User-defined scheme” for the test run naming.</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span style="">4.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Add some short prefix, e.g. MyRun</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span style="">5.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Uncheck “Append date-time stamp”</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span style="">6.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Save the test run configuration and retry the run.</span></p> <p><span style="font-size:9.5pt;color:black"></span>Again, I am sorry about this problem and I will make sure that it won’t appear in the next version.</span></p> <p><span style="font-size:9.5pt;color:black"> </span></p> <p><span style="font-size:9.5pt;color:black">Regards,</span></p> <p><span style="font-size:9.5pt;color:black">Boris</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><font face=Calibri> </font></p> <p></span></p>Tue, 08 Aug 2006 18:20:26 Z2006-08-09T18:40:00Zhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#be56fd93-f3ba-4c2f-880d-3256e60fb242http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#be56fd93-f3ba-4c2f-880d-3256e60fb242Peter Ritchiehttp://social.msdn.microsoft.com/Profile/en-US/?user=Peter%20RitchieUnit test AppDomain names and custom performance counters<div class=quote><table width="85%"><tr><td class=txt4> <strong>Boris Vidolov MSFT wrote:</strong></td></tr><tr><td class=quoteTable><table width="100%"><tr><td width="100%" valign=top class=txt4> <p><span style="font-size:9.5pt;color:black">Hello Peter,</span></p> <p><span style="font-size:9.5pt;color:black">Yes, you are right - the name of the AppDomain is in the form above. We are currently changing the design around creation of the AppDomains for the next version of Visual Studio. The following steps will make that name shorter and could potentially fix the problem for you:</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span>1.<span style="font:7pt 'Times New Roman'">     </span></span></span><span style="font-size:9.5pt;color:black">Edit the test run configuration file in an XML editor and modify the following two fields:</span></p> <p class=MsoNormal style="margin:0in 0in 0pt;line-height:normal"><span style="font-size:10pt;color:blue;font-family:'Courier New'"></span><font face=Calibri>&lt;</span></font><span style="font-size:10pt;color:#a31515;font-family:'Courier New'">userDeploymentRoot</span><span style="font-size:10pt;color:blue;font-family:'Courier New'"> </span><span style="font-size:10pt;color:red;font-family:'Courier New'">type</span><span style="font-size:10pt;color:blue;font-family:'Courier New'">=</span><span style="font-size:10pt;font-family:'Courier New'">&quot;<span style="color:blue">System.String</span>&quot;<span style="color:blue">&gt;</span><font style="background-color:#ffff00">c:\temp</font><span style="color:blue">&lt;/</span><span style="color:#a31515">userDeploymentRoot</span><span style="color:blue">&gt;</span></span></p> <p class=MsoNormal style="margin:0in 0in 0pt;line-height:normal"><span style="font-size:10pt;color:blue;font-family:'Courier New'">&lt;</span><span style="font-size:10pt;color:#a31515;font-family:'Courier New'">useDefaultDeploymentRoot</span><span style="font-size:10pt;color:blue;font-family:'Courier New'"> </span><span style="font-size:10pt;color:red;font-family:'Courier New'">type</span><span style="font-size:10pt;color:blue;font-family:'Courier New'">=</span><span style="font-size:10pt;font-family:'Courier New'">&quot;<span style="color:blue">System.Boolean</span>&quot;<span style="color:blue">&gt; </span><font style="background-color:#ffff00">False</font><span style="color:blue">&lt;/</span><span style="color:#a31515">useDefaultDeploymentRoot</span><span style="color:blue">&gt;</span></span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span>2.<span style="font:7pt 'Times New Roman'">     </span></span></span><span style="font-size:9.5pt;color:black">Save the file and open it in the test run configuration editor</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span>3.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Go to “General” pane, set “User-defined scheme” for the test run naming.</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span>4.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Add some short prefix, e.g. MyRun</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span>5.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Uncheck “Append date-time stamp”</span></p> <p style="margin-left:0.25in;text-indent:-0.25in"><span style="font-size:9.5pt;color:black"><span>6.<span style="font:7pt 'Times New Roman'">     </span></span></span></span><span style="font-size:9.5pt;color:black">Save the test run configuration and retry the run.</span></p> <p><span style="font-size:9.5pt;color:black"></span>Again, I am sorry about this problem and I will make sure that it won’t appear in the next version.</span></p> <p><span style="font-size:9.5pt;color:black"> </span></p> <p><span style="font-size:9.5pt;color:black">Regards,</span></p> <p><span style="font-size:9.5pt;color:black">Boris</span></p> <p class=MsoNormal style="margin:0in 0in 10pt"><font face=Calibri> </font></p> <p></span></p> <p></td></tr></table></td></tr></table></div>Thanks, Boris.  Just gave it a try and it is a valid workaround.</p> <p><font face=Verdana>Thanks again.</font></p>Wed, 09 Aug 2006 18:41:07 Z2006-08-09T18:41:07Zhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#6f4aa513-56d8-4d1a-9f41-408898cfd3b7http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#6f4aa513-56d8-4d1a-9f41-408898cfd3b7Enoc Parduehttp://social.msdn.microsoft.com/Profile/en-US/?user=Enoc%20PardueUnit test AppDomain names and custom performance counters<p align=left>Hi Boris, </p> <p align=left> </p> <p align=left>The problem still exists in the Unit Testing code that ships with VS2008 Beta2, about 1 year after you said you would not let the next version ship with it (unless you mean the RTM).  Also, the workaround does not work in VS2008 Beta2.  I resorted to creating a special folder structure off of C:\ in order to ensure that the working path of the project was short enough to avoid making the AppDomain name longer than 127 characters. </p> <p> </p> <p align=left>Regards,</p> <p align=left>Enoc Pardue</p>Thu, 04 Oct 2007 01:37:20 Z2007-10-04T01:37:20Zhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#dcbe1f8f-15ee-47a9-b5c3-86fbbdb1e992http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#dcbe1f8f-15ee-47a9-b5c3-86fbbdb1e992Peter Ritchiehttp://social.msdn.microsoft.com/Profile/en-US/?user=Peter%20RitchieUnit test AppDomain names and custom performance counters<p>Enoc, I opened a bug about this on Connect around the time I created this thread.  See <a title="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=176361" href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=176361">https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=176361</a>  Voting/validation, I'm told, increases the likelihood the bug will get fixed.  I'm trying to followup on what's going on with this issue in Orcas.</p>Thu, 04 Oct 2007 15:24:23 Z2007-10-04T15:24:23Zhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#42c90dff-df1a-4c8e-90ba-083d754c4420http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#42c90dff-df1a-4c8e-90ba-083d754c4420Jay Thalerhttp://social.msdn.microsoft.com/Profile/en-US/?user=Jay%20ThalerUnit test AppDomain names and custom performance counters<p align=left><font face=Arial size=2></font> </p> <p>It looks like they closed your Connect entry without giving any solution or workaround.  There is something you can do, though.</p> <p align=left> </p> <p align=left>In the testrunconfig file, you can add an element similar to the following:</p> <p align=left>&lt;NamingScheme baseName=&quot;MyTests&quot; appendTimeStamp=&quot;false&quot; useDefault=&quot;false&quot; /&gt;</p> <p align=left> </p>Thu, 21 Aug 2008 18:31:45 Z2008-08-21T18:31:45Zhttp://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#73f2ed84-1949-4543-9ff9-23f82ad82140http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/c3160fc2-2fa6-49f1-b033-61cd099d1107#73f2ed84-1949-4543-9ff9-23f82ad82140Peter Ritchiehttp://social.msdn.microsoft.com/Profile/en-US/?user=Peter%20RitchieUnit test AppDomain names and custom performance counters<div class=quote> <table width="85%"> <tbody> <tr> <td class=txt4> <strong>Jay Thaler wrote:</strong></td></tr> <tr> <td class=quoteTable> <table width="100%"> <tbody> <tr> <td class=txt4 valign=top width="100%"> <p align=left><font face=Arial size=2></font> </p>It looks like they closed your Connect entry without giving any solution or workaround.</td></tr></tbody></table></td></tr></tbody></table></div>Yep, they're suggesting it's an external problem.  I've given up on the issue.Thu, 21 Aug 2008 18:33:14 Z2008-08-21T18:33:14Z