0

I have a windows service written in C# and installed on my machine by using the installUtil.exe utility. After the installation completes successfully, I am trying to start the service. However it is giving me a 1053 error.

Now the truly weird thing is that when I delete the Config file the service starts just fine (Although then it stops because of a null pointer Exception, which is to be expected since there is no config file).

Any insights on this? I'm at loss here I've installed another service on the same machine which works just fine.

Note: the OS is Windows 7 Home Premium x64

edit =======

To make it clear, I tried logging (using the event Viewer) in the OnStart() Method. When the log file is deleted I can see all the log entries and the service works fine up to the point where it needs to get data from the config file.

The problem seems to be when the config file is still present. The first line of the OnStart() Method makes a log entry, HOWEVER, the program is not reaching this point.

edit 2 ========================

protected override void OnStart(string[] args)
    {
        try
        {
            this.EventLog.WriteEntry("Starting Focus Stock Service");

This log entry is being logged only if the config file is not present otherwise it will not get to this point.

> <?xml version="1.0"?> <configuration>   <appSettings>
>     <add key="Directory" value="C:\Logs\FocusCommon"/>
>     <add key="FileName" value="log"/>
>     <add key="LogLevel" value="3"/>
>     <add key="StockRemotingServerPort" value="10001"/>
>     <add key="StockRemotingServerName" value="FocusStockServer"/>
>     <add key="SQLServerConnStringTemplate" value="server=$server$;uid=$username$;pwd=$password$;database=$database$;MultipleActiveResultSets=True;Pooling=False;"/>
>     <add key="AccountingSynchIntervalMinutes" value="1"/>
>     <add key="LocalImageDirectory" value="C:\Focus360_Image_Dir"/>
>     <add key="LocalBrandImageDirectory" value="C:\Focus360_Image_Dir\Brands"/>
>     <add key="LocalAttachmentDirectory" value="C:\Focus360_Attachment_Dir"/>
>     <add key="EmailServer" value="maltanet.net" />
>     <add key="EmailPort" value="25" />
>     <add key="EmailUserName" value="" />
>     <add key="EmailPassword" value="" />
>     <add key="EmailUseSSL" value="false" />   </appSettings>
<runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="FSS_SQLConnPool" publicKeyToken="40FEE7F833FAA042" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-1.0.4525.28539" newVersion="1.0.4525.28539"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Jonny
  • 2,787
  • 10
  • 40
  • 62
  • It sounds like there are some runtime exceptions being thrown from within the service in both cases. Any chance you can find out what those are? You might have to add some error logging to the code and re-deploy to get more useful information. But exception types, exception messages, and stack traces are very useful in this regard. – David Jun 24 '13 at 17:03
  • Yes I am logging using event viewer however in the case where the config file is not deleted it doesn't seem to be invoking the OnStart() method. After I delete the Config file then I see the log entries. – Jonny Jun 24 '13 at 17:06
  • When the config file is deleted it is stopping yes, but that is because it doesn't find the config file. So it seems that the config file is the problem – Jonny Jun 24 '13 at 17:07
  • I once had a working service that stopped working suddenly. It also logged it's condition in OnStart(). The cause turned out to be the event log was full. – jac Jun 24 '13 at 17:28

2 Answers2

2

This is the one thing that can go wrong when you start a service, other than it plain crashing. Your OnStart() method has 30 seconds to finish the job and return. If it takes longer then the service control manager assumes there is something seriously wrong, stops waiting for your service to start and produces error 1053, "The service did not respond to the start or control request in a timely fashion".

You can ask for additional time by calling RequestAdditionalTime(). But some odds that there is something basically wrong with your OnStart() code, 30 seconds is rather a long time to get a service started. Improve the odds to diagnose this problem by improving the logging in your code so you'll know where it gets stuck.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • without a config file the service starts immediately and logging in the in the OnStart method is not working (with the config file present). It seems like it the OnStart Method is not being invoked at all – Jonny Jun 24 '13 at 17:17
  • A config file has many powers but preventing OnStart from running isn't one of them. I'd assume that your code actually using, say, a setting in the config file sends it off into lala-land. Not sure why I have to guess what's in the config file though, you are not helping me help you. A general strategy to get a service working is to first make sure that it is flawless as a console mode app, where your Main() method does what OnStart() does. – Hans Passant Jun 24 '13 at 17:26
  • Well, it's what I assumed. Like using the connection string to contact a dbase server and it isn't online. As commented, make it work in a console mode app first. – Hans Passant Jun 24 '13 at 17:44
1
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

Ok so this seemed to be the problem. I'm not entirely sure why this was preventing it from starting on my machine. (Yes I tried on two other machines and the service started just fine !!!)

Anyways I removed this line and the service started on my machine as well.

Jonny
  • 2,787
  • 10
  • 40
  • 62