Service does not respond to management function (error 2186)

I am developing a service using .NET platforms on Windows.

He worked until yesterday ... but today he does not want to start !!! Seems strange and I feel like something is missing ...

I also tried returning the sources to the latest working version, but nothing else happens: clean starting outputs:

The service does not respond to the management function.

What can cause this malfunction?


Most of you probably want to know more about this. So let me show you the code:

Service Code:

#if DEBUG class iGeckoService : DebuggableService #else class iGeckoService : ServiceBase #endif { static void Main() { #if DEBUG if (Debugger.IsAttached == true) { DebuggableService[] services = Services; // Create console AllocConsole(); // Emulate ServiceBase.Run foreach (DebuggableService service in services) service.Start(null); // Wait for new line Console.WriteLine("Press ENTER to exit..."); Console.ReadLine(); // Emulate ServiceBase.Run foreach (DebuggableService service in services) service.Stop(); } else ServiceBase.Run(Services); #else ServiceBase.Run(Services); #endif } #if DEBUG static DebuggableService[] Services { get { return (new DebuggableService[] { new iGeckoService() }); } } [DllImport("kernel32")] static extern bool AllocConsole(); #else static DebuggableService[] Services { get { return (new ServiceBase[] { new iGeckoService() }); } } #endif #endregion #region Constructors /// <summary> /// Default constructor. /// </summary> public iGeckoService() { // Base properties ServiceName = DefaultServiceName; // Service feature - Power events } #endregion protected override void OnStart(string[] args) { try { ... } catch (Exception e) { sLog.Error("Unable to initialize the service. Request to stop.", e); } } /// <summary> /// Stop this service. /// </summary> protected override void OnStop() { ... } } [RunInstaller(true)] public class iGeckoDaemonInstaller : Installer { /// <summary> /// Default constructor. /// </summary> public iGeckoDaemonInstaller() { ServiceProcessInstaller spi = new ServiceProcessInstaller(); spi.Account = ServiceAccount.LocalSystem; ServiceInstaller si = new ServiceInstaller(); si.ServiceName = iGeckoService.DefaultServiceName; si.StartType = ServiceStartMode.Automatic; Installers.AddRange(new Installer[] {spi, si}); } } class DebuggableService : ServiceBase { public void Start(string[] args) { OnStart(args); } } 

Running script:

 installutil ..\bin\Debug\iGeckoService.exe net start "Gecko Videowall" 

while stopping the script:

 net stop "Gecko Videowall" installutil /u ..\bin\Debug\iGeckoService.exe 

However, I think this is a system setting, as the application works well until the last day. (Sigh).


Update

When the service was running, I used log4net to register the activity of the service (I cannot connect the debugger to the running service ...), and it was always registered.

Now log4net is never created (even if I turn on the internal debugging option), even if I enter the main program!


Another update

It seems that the application is never running. I have reduced each routine (Main, OnStart, OnStop) and I am starting an empty service. The OnStart procedure creates a file in the directory (it is completely written by everyone), but when the service starts, the file is not created.


Another update

Stimulated by Rob's comment, I saw this post in the event viewer:

 > Faulting application name: iGeckoService.exe, version: 1.0.0.0, time stamp: 0x4c60de6a > Faulting module name: ntdll.dll, version: 6.1.7600.16385, time stamp: 0x4a5be02b > Exception code: 0x80000003 > Fault offset: 0x000000000004f190 > Faulting process id: 0x1258 > Faulting application start time: 0x01cb384a726c7167 > Faulting application path: C:\Users\Luca\Documents\Projects\iGeckoSvn\iGeckoService\bin\Debug\iGeckoService.exe > Faulting module path: C:\Windows\SYSTEM32\ntdll.dll > Report Id: b096a237-a43d-11df-afc4-001e8c414537 

This is certainly the reason for disabling the service ... not the question: “ How to debug it? ” (Thanks Rob, I never thought about viewing events until Now!) Debugging running as a console application does not cause any bugs, indeed, it seems that this is due to the service environment. The only thing that comes to my mind may be a failure in loading the DLL, because now the service is empty ... any idea?

(Thanks to everyone for following me ... I would like to offer you pizza and beer)


Solved!

The service could not start from the moment of failure before the main procedure caused by the installation and installation of MS Application Verifier (x64). After uninstalling this application everything worked as usual!

Thanks everyone!

+7
c # windows service
source share
4 answers

In general, each service should do two simple things.

  • if the service manager sends him a control code, such as SERVICE_CONTROL_START , SERVICE_CONTROL_STOP , etc., if he must return after a short period of time. Using the function function SetServiceStatus can SetServiceStatus this interval, for example, by calling SetServiceStatus with an increased value of dwCheckPoint . (In .NET, use can use ServiceBase.RequestAdditionalTime instead)
  • each service must respond with the SERVICE_CONTROL_INTERROGATE control code only with a return. This control code is used by the service manager to determine if the service is still running.

If your program does not follow one of the rules, you get the error message "The service is not responding to the management function."

If you are writing a program in .NET, you do not need to do the two things that I described earlier. The ServiceBase class will do there for you. However, you can easily break these rules if you create a thread that works with a higher priority, as usual, or if you do too long work inside the OnStop descriptor ( OnStop , OnStart , OnPowerEvent etc.) without calling ServiceBase.RequestAdditionalTime . Some other tricks with extra threads can also cause problems.

+5
source share

This usually happens if you try to do too much work in an OnStart call. For example, if you start an infinite loop in the same thread, you will get this error message.

Typically, a service should create a new thread in an OnStart call, and then cleanly terminate it in an OnStop call.

Of course, this will not help if you use previously working code. Did you try to restart it after a crash? I seem to remember that if you already have a service that has been bitten, it can sometimes be difficult to return to working condition without restarting it. You can look in your list of processes and see if you still have a copy, and kill it, if so.

+3
source share

I see that there is a code block

 // Wait for new line Console.WriteLine("Press ENTER to exit..."); Console.ReadLine(); 

as pointed out by @Jon as it is a service. when the service starts, it waits for the set time during which it should respond.

the " Console.ReadLine() " instruction appears, which you will wait until the key is pressed. as this service will continue to wait at this point

0
source share

For me, it simply meant an exception was made. (A platform conflict in Configuration Manager resulting in an "incorrect image format.") Try running .exe from the command line and see if an error occurs.

0
source share

All Articles