all groups > visual studio .net enterprise tools > august 2006 >
You're in the

visual studio .net enterprise tools

group:

Unit testing web service reference results in InvalidOperationExce



Unit testing web service reference results in InvalidOperationExce Peter Ritchie [C# MVP]
8/4/2006 11:54:02 AM
visual studio .net enterprise tools: I'm getting a really strange InvalidOperationException exception when trying
to invoke a web service method from within a unit test.

The message from the exception is "Instance names used for writing to custom
counters must be 127 characters or less." You can imagine my bewilderment at
the message because I do not use custome counters in my unit test or in the
web service.

Looking at the stack I see a call to
System.Diagnostics.SharedPerformanceCounter's ctor. And to my surprise I see
parameters like:

(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)

[were sensitive data is replaced char-for-char by 'X']

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.

I get the impression this string is the name of the AppDomain for the unit
test. Is there anything I can do to get around this?

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
RE: Unit testing web service reference results in InvalidOperationExce stcheng NO[at]SPAM online.microsoft.com
8/7/2006 12:00:00 AM
Hello Peter,

As for the InvalidOperationException, it is likely the Visual Studio 2005
unit test host appliation will write some trace data into the shared
performance counter, and the long instance name (derived from project's
path name and project component name) will result to the exception.

I've performed some simple test(through the VS 2005 unit test project)
against an ASP.NET webservice (also put the project in a deep directory
path and name the test class with a long name) , however I haven't been
able to reproduce the same error. What's your test project's test class,
is it also just containing a simple [testmethod] that construct the
webservice proxy and call the webservice?

As for the vs 2005 unit test project, its output is a class library
assembly and it is the "VsTestHost.exe" which actually load our unit test
assembly and host it. I've performed some general investigation upon the
vstesthost.exe, since the app.config file doesn't contain explicit
performance counter or tracing setting. It should be the Visual Studio Test
Tools class which call the SharedPerfromanceCounter internally. Would you
share me the complete call stack you get ?

Also, if convenient, you can provide me a simplified test project so that I
can test it against my local webservice in my local environment.

Please let me know if there is anything I missed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
RE: Unit testing web service reference results in InvalidOperation Peter Ritchie [C# MVP]
8/10/2006 10:14:02 AM
Hi Steven. Thank you for your response.

I've received some feedback from Boris Vidolov on the VSTS team that this is
a known issue and presented the following workaround to force the the binary
into a different, shorter path. Add/change the following elements in the
..testrunconfig file:

<userDeploymentRoot type="System.String">c:\temp</userDeploymentRoot>

<useDefaultDeploymentRoot type="System.Boolean">
False</useDefaultDeploymentRoot>

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


[quoted text, click to view]
RE: Unit testing web service reference results in InvalidOperation stcheng NO[at]SPAM online.microsoft.com
8/11/2006 2:55:28 AM
Thanks for your folloup Peter,

Glad that you've got progress on this issue. I've also found your feedback
entry in the Visual Studio feedback center. As for this issue, I'd like to
make a brief summary below in case any other member may also suffer the
same problem:

======PROBLEM:===================

When performing unit testing in visual studio 2005 test project, it report
an "InvalidOperationException" with the below message:

"Instance names used for writing to custom counters must be 127 characters
or less."


#reference product feedback link
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?Feedbac
kID=176361

======CAUSE ======
vs test host internally use long path name for shared perfcounter's naming
and exceed the 127 chars limit.


====CURRENT WORK AROUND=========

Force the the binary into a different, shorter path. Add/change the
following elements in the ".testrunconfig" file:

<userDeploymentRoot type="System.String">c:\temp</userDeploymentRoot>

<useDefaultDeploymentRoot type="System.Boolean">
False</useDefaultDeploymentRoot>

=========================================

Again, thanks for your posting and the information.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.



RE: Unit testing web service reference results in InvalidOperation Peter Ritchie [C# MVP]
8/11/2006 6:44:01 AM
Hi Steven. I haven't had a chance to update the feedback entry with the
workaround, so thanks for doing that... Your summary and workaround seem to
capture all the details.

-- Peter
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


[quoted text, click to view]
AddThis Social Bookmark Button