473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

.Net (C#) Service Fails To Start

I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken
Nov 17 '05 #1
29 3373
One technique you could try if all else fails is to insert a try/catch block
around all of the code in your OnStart() method and show any errors in a
message box. Note this will require your service to have the "Interact With
Desktop" permission. Alternately, you could write the message to a known
file on disk.

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
http://blogs.msdn.com/jaredpar
"This posting is provided "AS IS" with no warranties, and confers no rights"
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of late),
there is an entry in the Event Log immediately after a boot indicating that
the service failed to start after 30,000 milliseconds. Usually it starts
fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when it
fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems to
succeed. Interestingly, launching as a console application is about 10
times faster than starting the service! In no case that the service loaded
properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken

Nov 17 '05 #2
But the problem is that none of the code in the main() routine, which
must execute before the OnStart(), is producing output in this case
either. It is just as if the program was not able to launch -- but it
does launch since it appears in the list of services once the system
permits a logon!

-ken

Jared Parsons [MSFT] wrote:
One technique you could try if all else fails is to insert a try/catch block
around all of the code in your OnStart() method and show any errors in a
message box. Note this will require your service to have the "Interact With
Desktop" permission. Alternately, you could write the message to a known
file on disk.

Nov 17 '05 #3

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
But the problem is that none of the code in the main() routine, which must
execute before the OnStart(), is producing output in this case either. It
is just as if the program was not able to launch -- but it does launch
since it appears in the list of services once the system permits a logon!

-ken

Jared Parsons [MSFT] wrote:
One technique you could try if all else fails is to insert a try/catch
block around all of the code in your OnStart() method and show any errors
in a message box. Note this will require your service to have the
"Interact With Desktop" permission. Alternately, you could write the
message to a known file on disk.


What exactly are you doing in your OnStart? Are you Impersonating or are you
accessing network resources?

Willy.
Nov 17 '05 #4
In this service, the only thing that OnStart() does is create and start
a thread; the thread creates a named pipe and then processes the
information sent over the pipe until the thread exits. I have added some
debug code to create Event Log entries, but they, along with the debug
Event Log entries created in the main() routine, only appear if the
service starts. In the case where I get this error, which I can only
reproduce at boot time, there are no Event Log entries produced other
than the one from the service manager reporting that my service failed
to respond within 30,000 milliseconds.

Again, all of the .Net services I wrote launch fine most of the time,
but on upon occasion they exhibit this error on the boot of the system.
I cannot detect anything different, as not all boots on the same system
exhibit the same error! And the services all seem to start manually once
the system is booted.

-ken

Willy Denoyette [MVP] wrote:
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
But the problem is that none of the code in the main() routine, which must
execute before the OnStart(), is producing output in this case either. It
is just as if the program was not able to launch -- but it does launch
since it appears in the list of services once the system permits a logon!

-ken

Jared Parsons [MSFT] wrote:
One technique you could try if all else fails is to insert a try/catch
block around all of the code in your OnStart() method and show any errors
in a message box. Note this will require your service to have the
"Interact With Desktop" permission. Alternately, you could write the
message to a known file on disk.

What exactly are you doing in your OnStart? Are you Impersonating or are you
accessing network resources?

Willy.

Nov 17 '05 #5
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
Again, all of the .Net services I wrote launch fine most of the time, but
on upon occasion they exhibit this error on the boot of the system. I
cannot detect anything different, as not all boots on the same system
exhibit the same error! And the services all seem to start manually once
the system is booted.


Make sure that you have your service dependencies set correctly so that all
required services are running before yours...

-- Alan
Nov 17 '05 #6
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?


Sorry, I did not read your post carefully enough before my last post.

There are no services for .NET itself. Try adding RPC as a dependency for
your service. For this you enter RPCSS in your dependency list. If built
and (re)installed correctly, you should see "Remote Procedure Call (RPC)" in
the Dependencies tab for the service in the SCM.

-- Alan
Nov 17 '05 #7

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
In this service, the only thing that OnStart() does is create and start a
thread; the thread creates a named pipe and then processes the information
sent over the pipe until the thread exits. I have added some debug code to
create Event Log entries, but they, along with the debug Event Log entries
created in the main() routine, only appear if the service starts. In the
case where I get this error, which I can only reproduce at boot time,
there are no Event Log entries produced other than the one from the
service manager reporting that my service failed to respond within 30,000
milliseconds.

Again, all of the .Net services I wrote launch fine most of the time, but
on upon occasion they exhibit this error on the boot of the system. I
cannot detect anything different, as not all boots on the same system
exhibit the same error! And the services all seem to start manually once
the system is booted.

-ken


Add "Network Connections" to the dependencies.

Willy.
Nov 17 '05 #8
Alan Pretre wrote:
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
Again, all of the .Net services I wrote launch fine most of the time, but
on upon occasion they exhibit this error on the boot of the system. I
cannot detect anything different, as not all boots on the same system
exhibit the same error! And the services all seem to start manually once
the system is booted.

Make sure that you have your service dependencies set correctly so that all
required services are running before yours...

-- Alan

But there are no dependencies that I am aware of, other than possibly
the Event Log.

-ken
Nov 17 '05 #9
Willy Denoyette [MVP] wrote:
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
In this service, the only thing that OnStart() does is create and start a
thread; the thread creates a named pipe and then processes the information
sent over the pipe until the thread exits. I have added some debug code to
create Event Log entries, but they, along with the debug Event Log entries
created in the main() routine, only appear if the service starts. In the
case where I get this error, which I can only reproduce at boot time,
there are no Event Log entries produced other than the one from the
service manager reporting that my service failed to respond within 30,000
milliseconds.

Again, all of the .Net services I wrote launch fine most of the time, but
on upon occasion they exhibit this error on the boot of the system. I
cannot detect anything different, as not all boots on the same system
exhibit the same error! And the services all seem to start manually once
the system is booted.

-ken

Add "Network Connections" to the dependencies.

Willy.

Why, since the program does nothing with the network?

-ken
Nov 17 '05 #10
Alan Pretre wrote:
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

Sorry, I did not read your post carefully enough before my last post.

There are no services for .NET itself. Try adding RPC as a dependency for
your service. For this you enter RPCSS in your dependency list. If built
and (re)installed correctly, you should see "Remote Procedure Call (RPC)" in
the Dependencies tab for the service in the SCM.

-- Alan

I have added this to the code and we are testing now, but why would this
have an effect?

-ken
Nov 17 '05 #11
Having suffered through getting a C# service going, here's a trick that
I did that helped me track things down. In your OnStart function, put a
line at the beginning like "Thread.Sleep(20000)" and put a breakpoint at
the following line. Start your service, then quickly go back into
Visual Studio and hit Debug, Processes and attach to your service
(you'll probably need to check "Show system processes"). Once you do
that, your debugger is attached to the service and you can step through
once the Sleep is done and find out where things are going wrong.
Ken Allen wrote:
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken

Nov 17 '05 #12
Interesting technique - but when my code fails, it does not seem to even
get that far, and when it succeeds, I have no need to debug it, and I
cannot predict when it will fail.

-ken

Jason wrote:
Having suffered through getting a C# service going, here's a trick that
I did that helped me track things down. In your OnStart function, put a
line at the beginning like "Thread.Sleep(20000)" and put a breakpoint at
the following line. Start your service, then quickly go back into
Visual Studio and hit Debug, Processes and attach to your service
(you'll probably need to check "Show system processes"). Once you do
that, your debugger is attached to the service and you can step through
once the Sleep is done and find out where things are going wrong.
Ken Allen wrote:
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service
cannot execute?

How can I define any dependencies at compile time? The
ServiceInstaller permits me to define a list of services to depend on,
but there does not seem to be any dependency on other objects. Nor
does there appear to be any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load,
but only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect
would that have on my service?

-ken

Nov 17 '05 #13

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
Willy Denoyette [MVP] wrote:
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:Ok**************@tk2msftngp13.phx.gbl...
In this service, the only thing that OnStart() does is create and start a
thread; the thread creates a named pipe and then processes the
information sent over the pipe until the thread exits. I have added some
debug code to create Event Log entries, but they, along with the debug
Event Log entries created in the main() routine, only appear if the
service starts. In the case where I get this error, which I can only
reproduce at boot time, there are no Event Log entries produced other
than the one from the service manager reporting that my service failed to
respond within 30,000 milliseconds.

Again, all of the .Net services I wrote launch fine most of the time, but
on upon occasion they exhibit this error on the boot of the system. I
cannot detect anything different, as not all boots on the same system
exhibit the same error! And the services all seem to start manually once
the system is booted.

-ken

Add "Network Connections" to the dependencies.

Willy.

Why, since the program does nothing with the network?

-ken


Not sure it doesn't, you use named pipes do you? Are your endpoints local
only? Note that if the Server service is running, all named pipes are
accessible remotely. If you only need local endpoints you should deny access
to NT_AUTHORITY\NETWORK or use local RPC.

Willy.

Nov 17 '05 #14

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:O3**************@tk2msftngp13.phx.gbl...
Alan Pretre wrote:
"Ken Allen" <ke******@sympatico.ca> wrote in message
news:eV**************@TK2MSFTNGP15.phx.gbl...
I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

Sorry, I did not read your post carefully enough before my last post.

There are no services for .NET itself. Try adding RPC as a dependency
for your service. For this you enter RPCSS in your dependency list. If
built and (re)installed correctly, you should see "Remote Procedure Call
(RPC)" in the Dependencies tab for the service in the SCM.

-- Alan

I have added this to the code and we are testing now, but why would this
have an effect?

-ken


Because your named pipe endpoints are network endpoints that needs the RPC
service to run.
The server endpoints are registered with the RPC service.
The client of a named pipe establishes a connection with a pipe server by
calling the RPC service to resolve the server end-point.
Willy.
Nov 17 '05 #15
OK, I have been over this so many times that I am getting dizzy. I have
modified the configuration to add dependencies, but this makes no
difference at all.

I am becoming convinced that the services that are failing (which are
all .Net code) are doing so before they even attempt to execute. The
only 'evidence' that I have of this is that when I added code to the
programs to create Event Log entries in the Main() routine, when the
service fails to start, not even these are present. This would indicate
to me that there is a problem with launching the executable to begin
with, even though the service is loading properly at installation time.

By the way, these services are being loaded as part of a larger
installation, which requires a reboot. The services are not started
immediately after installation, and the errors are first reported after
the first reboot after the installation. The number of reboots that are
performed before the services start properly vary, and there does not
seemm to be any pattern. Not all system exhibit this problem, as some
systems reboot and the services start fine the first time.

I am running out of things to try here. Anyone have any further suggestions?

-ken

Ken Allen wrote:
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken

Nov 17 '05 #16

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:uk****************@TK2MSFTNGP15.phx.gbl...
OK, I have been over this so many times that I am getting dizzy. I have
modified the configuration to add dependencies, but this makes no
difference at all.

I am becoming convinced that the services that are failing (which are all
.Net code) are doing so before they even attempt to execute. The only
'evidence' that I have of this is that when I added code to the programs
to create Event Log entries in the Main() routine, when the service fails
to start, not even these are present. This would indicate to me that there
is a problem with launching the executable to begin with, even though the
service is loading properly at installation time.

By the way, these services are being loaded as part of a larger
installation, which requires a reboot. The services are not started
immediately after installation, and the errors are first reported after
the first reboot after the installation. The number of reboots that are
performed before the services start properly vary, and there does not
seemm to be any pattern. Not all system exhibit this problem, as some
systems reboot and the services start fine the first time.

I am running out of things to try here. Anyone have any further
suggestions?

-ken


That would mean the process is not beeing created by the Service Control
Manager. The SCM creates a process using Win32 CreateProcessAsUser() using
the executable name and the user access token that represents the
useraccount as registered during install.
The token is obtained by the SCM by calling 'LogonUser' prior to the
'CreateProcessAsUser' call, using the credentials specified during service
install (if it's a user account).
When one of the calls to 'LogonUser' or 'CreateProcess' fails the SCM should
write an event to the System log, but it looks like you don't even see such
logs, right?
What happens when you start the service from the commandline using net start
<servicename>

Willy.

Nov 17 '05 #17
Willy Denoyette [MVP] wrote:

That would mean the process is not beeing created by the Service Control
Manager. The SCM creates a process using Win32 CreateProcessAsUser() using
the executable name and the user access token that represents the
useraccount as registered during install.
The token is obtained by the SCM by calling 'LogonUser' prior to the
'CreateProcessAsUser' call, using the credentials specified during service
install (if it's a user account).
When one of the calls to 'LogonUser' or 'CreateProcess' fails the SCM should
write an event to the System log, but it looks like you don't even see such
logs, right?
What happens when you start the service from the commandline using net start
<servicename>

Willy.

If the services are set to manual or are installed and started after the
sytem is running, then all proceeds without error. This only occurs on a
boot, only on some systems, and does not always occur. Even on a system
where this does occur, it may cease to occur any any subsequent reboot!

-ken
Nov 17 '05 #18
I have the same problem. My service works on most machines, but on some
(slow) machines the service doesn't start on system startup.

Are there any news about this problem?

regards, thilo.

Ken Allen schrieb:
Willy Denoyette [MVP] wrote:

That would mean the process is not beeing created by the Service Control
Manager. The SCM creates a process using Win32 CreateProcessAsUser() using
the executable name and the user access token that represents the
useraccount as registered during install.
The token is obtained by the SCM by calling 'LogonUser' prior to the
'CreateProcessAsUser' call, using the credentials specified during service
install (if it's a user account).
When one of the calls to 'LogonUser' or 'CreateProcess' fails the SCM should
write an event to the System log, but it looks like you don't even see such
logs, right?
What happens when you start the service from the commandline using net start
<servicename>

Willy.

If the services are set to manual or are installed and started after the
sytem is running, then all proceeds without error. This only occurs on a
boot, only on some systems, and does not always occur. Even on a system
where this does occur, it may cease to occur any any subsequent reboot!

-ken


Nov 17 '05 #19
I have the same problem with my service.

It seems that this problem occures only on a very slow machine (few RAM,
few CPU).

Are there any news concerning that problem?

Regards, Thilo.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #20
Still sounds like you might have a dependencies issue. Are you using
any other Windows services like MSMQ?

Nov 17 '05 #21
BravesCharm wrote:
Still sounds like you might have a dependencies issue. Are you using
any other Windows services like MSMQ?

No. One of the services does nothing but start the service thread, which
then instantiates the 'master' end of a pipe for communication from
other services (older code). The only code in the main() routine is
there to determine whether to instantiate the code as a service or as a
console application.

I have even placed debug code in the main() routine -- to produce Event
Log entries or to write to a disk file -- and if the service loads this
works fine, and if it fails no output whatsoever is produced. This leads
me to conclude that the main() routine is throwing some sort of
exception or the system initialization for the executable is failing,
but I can find no proof of this anywhere.

Oddly enough, if I modify the main() routine to contain any code that
performs file I/O, the problem seems to be far more difficult to
reproduce -- recently we have not been able to reproduce it at all. Even
simply having a line of code that reads as follows will seem to cause to
the problem to disappear: "Assembly.GetExecutingAssembly().Location;" (I
currently follow this line with another line that strips off the name of
the assembly in preparation for using the string to check for and even
read from another file in the same directory as the assembly itself).

I have two (2) services written in .Net and some older ones written in
C++, and the C++ services always atart, even when the .Net written
services do not. I can say that it is always a case of both of the .Net
services starting or neither of them starting, but I have not seen a
case where one of them starts and the other fails. This may be a side
effect of my experimienting with the one that is loaded first, so I
cannot be certain what this means.

-ken
Nov 17 '05 #22
is it possible that the .NET CLR isn't loaded entirely in this early
phase of the workstation startup? or something like that?

thilo.

Ken Allen schrieb:
BravesCharm wrote:
Still sounds like you might have a dependencies issue. Are you using
any other Windows services like MSMQ?
No. One of the services does nothing but start the service thread, which
then instantiates the 'master' end of a pipe for communication from
other services (older code). The only code in the main() routine is
there to determine whether to instantiate the code as a service or as a
console application.

.... -ken


Nov 17 '05 #23

"ThiloL" <th************@gmx.net> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
is it possible that the .NET CLR isn't loaded entirely in this early
phase of the workstation startup? or something like that?

thilo.


Hold on, the CLR isn't loaded as a service or a self containing process,
it's loaded in the application process space, it's just a run-time ( a bunch
of DLL's) like there are others like the VB6 runtime.

Willy.
Nov 17 '05 #24

"Ken Allen" <ke******@sympatico.ca> wrote in message
news:ur*************@TK2MSFTNGP12.phx.gbl...
BravesCharm wrote:
Still sounds like you might have a dependencies issue. Are you using
any other Windows services like MSMQ?

No. One of the services does nothing but start the service thread, which
then instantiates the 'master' end of a pipe for communication from other
services (older code). The only code in the main() routine is there to
determine whether to instantiate the code as a service or as a console
application.

I have even placed debug code in the main() routine -- to produce Event
Log entries or to write to a disk file -- and if the service loads this
works fine, and if it fails no output whatsoever is produced. This leads
me to conclude that the main() routine is throwing some sort of exception
or the system initialization for the executable is failing, but I can find
no proof of this anywhere.

My bet is that the (service) process didn't get started and obviously your
Main entry never called.
As I told you in another reply, the SCM creates the process for your
"service" by calling CreateProcessAs(..), things can go wrong when calling
this API, but the SCM should log an event when it fails.
One of the things that mostly fail is the creation of a logon session
(implicitely called by CreateProcessAs()) for the Service to run in, the
logon session is created using the identity as specified at service install
time. If the identity specified refers to a domain account and no DC is
reachable, the creation of the service process will fail (with an system and
security event logged).

So please apply Logon auditing using the Local Security Policy editor and
check your eventlog for Logon failures. Note that your service must depend
on Eventlog and RPCSS for this to work.

Willy.

Nov 17 '05 #25
OK, we have finally located the source of the problem in our shop!

Our first clues came when we examined the size of the binaries that
worked and the ones that did not - those that failed were almost 6000
bytes larger! We initially suspected the build environment, but testing
on another system that was configured with all of the latest revisions
of the tools produced the same large files.

Then we noticed that files build manually were smaller than those built
by our automated build process, and then it came to light - the binaries
that failed were being digitally signed! It seems the signing tool adds
some information to the binary image, and this messes up the .Net
assemblies. It does not mess them up enough that they do not work, but
enough that they will not always work when invoked during the boot process!

We have removed the digital signing of the .Net assemblies in our
automated build process and the problem appears to have disappeared, for
us at least.

-ken
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service cannot
execute?

How can I define any dependencies at compile time? The ServiceInstaller
permits me to define a list of services to depend on, but there does not
seem to be any dependency on other objects. Nor does there appear to be
any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load, but
only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect would
that have on my service?

-ken

Nov 17 '05 #26
Hi Ken,

I just happened to read this thread as I experienced the same problem a
couple of weeks ago. Up to now I did not find a solution so I am very
interested in yours. My problem is that I never intended to have a
digital signature and that I even do not know where it can be
de/-activated. I'd appreciate very much if you could give me a hint,
where I can change this in my project because it might solve my problem,
too.

By the way, in your first message you wrote:
How can I define any dependencies at compile time? The
ServiceInstaller permits me to define a list of services
to depend on Up to now I did not find where I can do that. If you could also give me
a hint on that !?

Thanks alot
Regards
Roland
Ken Allen schrieb: OK, we have finally located the source of the problem in our shop!

Our first clues came when we examined the size of the binaries that
worked and the ones that did not - those that failed were almost 6000
bytes larger! We initially suspected the build environment, but testing
on another system that was configured with all of the latest revisions
of the tools produced the same large files.

Then we noticed that files build manually were smaller than those built
by our automated build process, and then it came to light - the binaries
that failed were being digitally signed! It seems the signing tool adds
some information to the binary image, and this messes up the .Net
assemblies. It does not mess them up enough that they do not work, but
enough that they will not always work when invoked during the boot process!

We have removed the digital signing of the .Net assemblies in our
automated build process and the problem appears to have disappeared, for
us at least.

-ken
I have a number of services developed in C# (.Net), and they have been
working fine for the most part. Recently someone reported that ipon
occassion (originally rarely, but more frequently on some systems of
late), there is an entry in the Event Log immediately after a boot
indicating that the service failed to start after 30,000 milliseconds.
Usually it starts fine when attempting manually after the boot.

I instrumented the code to write entries to the Event Log during its
main() execution as well as during the OnStart() execution -- but when
it fails, there are no entries in the Event Log from the service code!

Attempting to launch the service as a console application always seems
to succeed. Interestingly, launching as a console application is about
10 times faster than starting the service! In no case that the service
loaded properly did the time pass the 500 milliseond duration!

I checked and there are no dependencies marked for the service. Is it
possible that .Net is not available at that time and the service
cannot execute?

How can I define any dependencies at compile time? The
ServiceInstaller permits me to define a list of services to depend on,
but there does not seem to be any dependency on other objects. Nor
does there appear to be any .Net service on which I could wait.

Does anyone have any ideas on why my service may be failing to load,
but only at boot time?

Where does the /LogToConsole=false switch setting come from on my
installed services? How do I change this to true, and what effect
would that have on my service?

-ken

Nov 17 '05 #27
Why not make a dump file using adplus -crash and than view the dump in
Windbg with SOS(Son Of Strike)?

Nov 17 '05 #28
nevermind, adplus cannot get a crash dump a startup app.

Nov 17 '05 #29
my service runs as "LocalSystem".

therefore "CreateProcessAs" is not the problem; I think.

the logon-event for "LocalSystem" in the eventlog - if the service
starts - is ok.

what else could I check?


*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Mazar | last post by:
I have a service which I create in vb.net. I'm trying to use the Recovery feature of Windows 2000/XP to restart the service if it fails to start. Looks like there are some steps that a service must...
2
by: Russ McDaniel | last post by:
Originally posted to microsoft.public.dotnet.distributed_apps with no response. Reposted here with additional thoughts. --- Hello, I'm writing a Windows service which performs some...
1
by: amirmira | last post by:
I have developed a service that monitors the CPU utilization performance counter and updates a table in a database. During the Service Start up, I attempt to connect to the database. I would like...
2
by: Shazad | last post by:
I am creating a windows service that requires parameters to start. The service Startup Type is set to automatic therefore it starts when the computer is started or rebooted. However the service...
14
by: Jasonkimberson | last post by:
Currently I am having a problem creating a windows service that monitors a mapped drive for events (using the FileSystemEventHandler). The service complies but fails to start: "The XMLWatcher...
5
by: SiD` | last post by:
when starting a windows service writte in vb.net, a messagebox appears: cannot start service from the command line or a debugger. A windows service must first be installed using installutil.exe ...
4
by: ThunderMusic | last post by:
Hi, We have many servers setup as a cluster. When one server crashes, another one take the relay... We want to know if it's possible (I suppose it is) to make a Windows service developed with .NET...
5
by: Benzi Eilon | last post by:
I have written a C# application which should run as a Windows Service. I must avoid having multiple instances of the application on one machine so I inserted the following code at the beginning of...
1
by: =?Utf-8?B?c3VyZmtlaXRo?= | last post by:
A machine running XP Home fails to start the cryptographic service. When attempting to start from the services menu it responds with error 2: the file specified cannot be found. I am unable to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.