Enterprise Library 1.1 with Instrumentation fails when used with Windows Service

Topics: Enterprise Library Core
Feb 26, 2007 at 5:48 PM
I am using Enterprise Library June 2005 release(1.1) in a windows service for mainly logging and exception handling. The service often fails to start with the following error in the event viewer.

The open procedure for service "WmiApRpl" in DLL "C:\WINDOWS\System32\wbem\wmiaprpl.dll" has taken longer than the established wait time to complete. There may be a problem with this extensible counter or the service it is collecting data from or the system may have been very busy when this call was attempted.

It works fine if I compile the Common assembly without USEWMI and USEPERFORMANCECOUNTER conditional compilation directives. But I use performance counters in the service and would like to get it working with instrumentation enabled. Has anyone encountered this before?
Mar 1, 2007 at 3:24 PM
Edited Mar 1, 2007 at 3:25 PM
I dug more into the issue and found that it hangs during the creation of PerformanceCounter. Further analysis revealed that it happens only when called during service process initialization. So if you refrain from putting any log messages or any other enterprise library related calls that could trigger a performance counter call during service initialization, you should be good to go. This is not an issue if you have logging in the OnStart method (service startup).

So in a nutshell, you can avoid this by either
1. Turning off WMI and Performance counters when you build enterprise library. See Tom Hollander's blog on this for more details http://blogs.msdn.com/tomholl/archive/2005/02/18/376187.aspx.
2. Avoid any calls to Enterprise Library during service initialization (ie., in static void Main() and service class constructor).

I still don't know the reason why it hangs during service initialization but not service startup, but this should provide a workaround for the issue.