PerformanceCounter constructor throwing an exception - incorrect security?  
Author Message
Pure Krome





PostPosted: Common Language Runtime, PerformanceCounter constructor throwing an exception - incorrect security? Top

Hi folks,
i have some customer performance counters in some data access layer code. On my localhost machine my unit tests (i'm using VSTS) all works perfectly fine. Using Perfmon i can see the graphs rise and fall as my counters increment and decrement. Sweet.

When i use the Team Build, which compiles the code on another build server box and then runs those VSTS unit tests the following exception is thrown:-

Test method <MyCustomMethod> threw exception: System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly..

After reading about the PerformanceCounter Constructor method it does state the following:-

http://www.hide-link.com/

Hmm. I'm not sure what this means. I'm guessing that for some weird reason, the 'user account' which the Team Build is using to do the unit tests does not have access to the performance counters. As such, is there any way PROGRAMATICALLY that i can tell the system to allow the code to run on that build server I tried adding the following line, but it still threw the exception:-

[assembly: System.Diagnostics.PerformanceCounterPermission(SecurityAction.RequestMinimum)]

Could anyone please help




.NET Development12