Creating Windows Services programatically - help

A

Amongin Ewinyu

Hi,

I'm trying to create a Windows service programmatically that will do the
following:

- When a user logs on, it will automatically run a service that uses BITS
(Background Intelligent Transfer Service) to check for the most current
version of a file and downloads this version.

I have a wrapper class thats imported as a reference in order for me to be
able to use BITS.

I am able to run and install the service into the SCM but when I attempt to
start the service I get the following message:

"The test service on Local Computer started and then stopped. Some services
stop automatically if they have no work to do, for example, the Performance
Logs and Alerts service."

I then see the following message logged in the Application Event viewer:

"
Service cannot be started. System.IO.FileNotFoundException: File or assembly
name Microsoft.Msdn.Samples.BITS, or one of its dependencies, was not found.

File name: "Microsoft.Msdn.Samples.BITS"

at testBits.startBits.OnStart(String[] args)

at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

=== Pre-bind state information ===

LOG: DisplayName = Microsoft.Msdn.Samples.BITS, Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null

(Fully-specified)

LOG: Appbase = C:\bits\testBits\obj\Debug\

LOG: Initial PrivatePath = NULL

Calling assembly : testBits, Version=1.0.2090.30051, Culture=neutral,
PublicKeyToken=null.

===

LOG: Policy not being applied to reference at this time (private, custom,
partial, or location-based assembly bind).

LOG: Post-policy reference: Microsoft.Msdn.Samples.BITS, Version=1.1.0.0,
Culture=neutral, PublicKeyToken=null

LOG: Attempting download of new URL
file:///C:/bits/testBits/obj/Debug/Microsoft.Msdn.Samples.BITS.DLL.

LOG: Attempting download of new URL
file:///C:/bits/testBits/obj/Debug/Microsoft.Msdn.Samples.BITS/Microsoft.Msdn.Samples.BITS.DLL.

LOG: Attempting download of new URL
file:///C:/bits/testBits/obj/Debug/Microsoft.Msdn.Samples.BITS.EXE.

LOG: Attempting download of new URL
file:///C:/bits/testBits/obj/Debug/Microsoft.Msdn.Samples.BITS/Microsoft.Msdn.Samples.BITS.EXE.

"

Could someone please tell me where i'm going wrong and/or what I need to
change.

Thanks.
 
C

Chris Dunaway

Amongin said:
I have a wrapper class thats imported as a reference in order for me to be
able to use BITS.

Have you tested the wrapper in a regular Windows Forms app to make sure
it works properly?
Service cannot be started. System.IO.FileNotFoundException: File or assembly
name Microsoft.Msdn.Samples.BITS, or one of its dependencies, was not found.

File name: "Microsoft.Msdn.Samples.BITS"

Is the wrapper file installed in the correct location? And are any
files it depends on also installed correctly?
 
A

Amongin Ewinyu

Yes I have tested the wrapper in a regular Windows form app. and it works
perfectly, the problem occurs when I try and use the same code in the
OnStart method of the Service class.

The wrapper depends on on two other files and they are all stored/installed
in the same location, which is the directory of the project.
- Is this the correct location?
- Is there a particular place that I need to install the wrapper file and
its dependencies for it to work?

Also I have noticed that the wrapper class and its dependencies do not have
any public key tokens, could this be causing the error?

Thanks, Amongin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top