Windows Service Starts then Stops

1.2k views Asked by At

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.
2

There are 2 answers

4
Andrew On

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.

0
Tim Lovell-Smith On

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