C# – Service did not start within a timely fashion – c# windows service

cservicevisual studio 2012

I have a Windows service which I can install on my local machine using installutil no problem.

Now, this service has to be installed on a server. I copy all files to the server and run the same command, set the service to log on as a local user account and when the service starts I get an error saying "logon failed" – okay so perhaps the user account is the issue.

So I change the service log on as to local system account. I start the service and I am told "The service did not respond to the start or control request in a timely fashion".

So I googled and tried various solutions but to no avail. So I got to thinking maybe it was something in the OnStart method which broke (even though I have logging calls which never logged). So I removed all code from the OnStart event and still the service would not start, I got the "timely fashion" error.

So where am I at? I believe it could be due to the references I have defined in the project. To test this I created a new Windows service template from VS2012 with no references (other than the default ones) and I can start the service. No issues.

So my question is what could be causing this? In my project the references point to locations which do not exist on the server, however the directory where the service resides has all the referenced DLLs.

Edit:
Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace RetrieveAndProcessSecurityLogs
{
    static class Program
    {
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
            new LogService()
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

LogService.cs

public partial class LogService : ServiceBase
{
    public LogService()
    {
        InitializeComponent();
        this.ServiceName = "Retrieve and Process Security Logs";
        this.CanPauseAndContinue = true;
        this.CanStop = true;
    }

    protected override void OnStart(string[] args)
    {
        //...
    }

    protected override void OnStop()
    {
        //...
    }

Edit: The installed .NET version on the server is v4.0, however in the app config file for the project there is this line:

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />

Could the 4.5 part be the issue?

Edit2: Bottom line: if I reference a DLL, I get the timely fashion error. If I have no extra DLL reference defined the service starts.

Sorry for the story.
Andrew

Best Answer

For future reference to anyone who encounters this issue, the issue was one of the references was built against .NET FW 4.5 and on the server where the service was being installed had .NET FW 4. My machine had 4.5.

Related Topic