Windows Service running on W2K3 but not working on W2K8 R2 RRS feed

  • Question

  • I do have a bunch of windows services (written in C#) that all use the same pattern - there's a class library which has a public Start and Stop method - and those methods are called by my service wrapper at the appropriate point in time. The class lib also has a main method and can run as standalone software - it's just a project configuration switch to decide if I want the actual program logic as a dll or an exe.

    So far so good - in recent days I made some changed to one of my services that had been running just fine on dozens of machines. When I wanted to upgrade though, I ran into some issues. My staging box is a W2K3 R2 box, and there I had no trouble running the newly compiled service (the service .exe file was left.. but dll was changed). Then I went to our production machines which use W2K8 R2, and then the following happend:

    The service controller reports that the service cannot be started. In the Event Viewer, I see an event 7009 ("A timeout was reached (30000 milliseconds) while waiting for the xyz service to connect"), then followed by an event 7000 ("The xyz service failed to start due to the following error: The service did not respond to the start or control request in a timely fashion").

    I then went ahead and changed the output type of my dll project to commandline, added the exe to the path where the service resides, copied, renamed the config file so it mached the lib.exe and ran the exe - and that works just fine.

    Then I went to another box - same behavior there... I can run the program but not the service.

    So I started checking if maybe I'm missing some libs, made sure the code dll and the service had all the same references. Then I added eventlog logging code to the Constructor of my service in the hope that it would at least tell me if it gets to InitializeComponent - but to no avail.. on those W2K8 R2 boxes, there are no event log entries from my service at all - so it doesn't even get there, let alone initialize the code in the dll (where I do have quit a bit of logging).

    I'm wondering if anybody has any idea what that could be or how I can get some more information on what is going wrong. In my experience, services that take very long then stop again do have a problem initializing.. but the service doesn't even get into the initialization code so I'm at my wits' end here

    Thursday, October 21, 2010 7:43 PM


All replies




    As far as I know, Windows Server 2008 R2 is 64bit only, what's your service application built as? AnyCPU or x86?

    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, October 22, 2010 6:09 AM
  • You are right on the money with your question.

    In the meantime, I tried running my service on my development box (Win7 64bit) and wouldn't you know, after the service refused to start, I actually got the error prompt where I'm asked if I wanted to debug.. and when I did, it showed me a BadImageFormatException. Turns out I have the main lib build as x86 (because there's no edit and continue in 64bit mode - I really wished that was added rather sooner than later), and the service was still set to all platforms (being one of many projects migrated from vs2008 on a 32bit box). After a rebuild to x86, things finally worked out.

    The question remains though.. why didn't I get the error prompt on the production machines? After all.. if I have the same issue with a commandline or GUI app, I do get the error prompt (which in turn allows me to see what exception has been thrown) on those machines.

    Also, what I haven't quite understood yet is why I can happily build certain apps that use a mix of AnyCPU and x86 in the underlying libs and it still works out (and edit&continue works) - and then from one day to the next, suddenly I do get the BadImageFormatException and have to rebuild a lib as x86. I'd understand if this was consistent (so no app would run if the main exe was x86 and some libs are AnyCPU) - but it seems to happen pretty much at random.. and once it happens, there's no going back to AnyCPU unless you change the entire build chain to AnyCPU.

    Friday, October 22, 2010 11:09 AM
  • You might not be seeing the error because there is extreme isolation between services and the interactive user on UAC systems for security reasons.


    Phil Wilson
    • Marked as answer by eryang Monday, November 1, 2010 3:17 AM
    Friday, October 22, 2010 6:15 PM
  • I understand the security angle - but shouldn't the service at least log the error (ideally in the event log)?

    We ran into something similar today.. deployed a service and somebody forgot to make sure the required .NET framework was there. Service registration uses installutil from .NET 2.0 so that worked but the service wouldn't start and since the error happened during base class initialization, there was none of our custom logging either.

    Only starting the app without service wrapper finally yielded an error message that eventually lead us to the root cause (I suppose that sooner or later we'll have to write an installer with the prerequisite check but it's always a matter of how much time you really gain... especially for server apps which are deployed on a single machine).

    Tuesday, November 2, 2010 5:09 PM