views:

272

answers:

2

I have a Windows Service that I inherited from a departed developer. The Windows Service is running just fine in the QA environment. When I install the service and run it locally, I receive this error:

Service cannot be started. System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.

Here is the code:

ExternalDataExchangeService exchangeService = new ExternalDataExchangeService();
            workflowRuntime.AddService(exchangeService);
            workflowRuntime.AddService(new SqlTrackingService(AppContext.SqlConnectionImportLog));
            ChallengerWorkflowService challengerWorkflowService = new ChallengerWorkflowService();
            challengerWorkflowService.SendDataEvent += new EventHandler<SendDataEventArgs>(challengerWorkflowService_SendDataEvent);
            workflowRuntime.AddService(challengerWorkflowService);
            workflowRuntime.StartRuntime(); <---- Exception is thrown here.
+1  A: 

Check for installer code. Often you will find counters are created within an installation (which is going to of been run under admin privledges on client site) and the code then uses them as though they exist - but will not try create them because they do not expect to have the permissions.

If you just get the source and then try run it, the counters / counter classes do not exist so you fall over immediately. (Alternatively check whether the counter exists / you have local admin if they wrote the code to create it in the service.)

Seen it before so mentioned it.

Andrew
You might want to increase the privileges of the service process user to see if that fixes the problem.
Hassan Syed
I cannot find any counters in app or installer. I am logged in as Admin on my PC.
Rich Blumer
Going to have to find from the code which counter it expects and track whether that is a custom one created by the developer, or a windows based one it expects to read. (It might lets say be an exchange app counter, and your QA box has exchange, but your development PC doesn't have exchange installed.)
Andrew
How do I find the counters from code?
Rich Blumer
The workflow startruntime is a red herring of an error, the error is within the wordflow, so you need to understand 'what' is being started and what code it executes.
Andrew
Ok, how do I do that?
Rich Blumer
A: 

Attach Debugger and break on InvalidOperationException (first-chance, i.e. when thrown)?

Tim Lovell-Smith