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!