By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,069 Members | 1,716 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,069 IT Pros & Developers. It's quick & easy.

Install Windows Service

P: n/a
Hi All,

I wrote a windows service with C# as below. But I can't install it with
installutil.exe. I got an error message "
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice1, or
one of its dependencies, was not found.. "
I am new to C# environment. Any idea any clue will be appreciated. Thanks

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.Configuration.Install;

namespace WindowsService1

{

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]

public class MyProjectInstaller: Installer

{

private ServiceInstaller serviceInstaller1;

private ServiceProcessInstaller processInstaller;

public MyProjectInstaller() :base()

{

// Attach the 'Committed' event.

this.Committed += new InstallEventHandler(MyInstaller_Committed);

// Attach the 'Committing' event.

this.Committing += new InstallEventHandler(MyInstaller_Committing);

// Instantiate installers for process and services.

processInstaller = new ServiceProcessInstaller();

serviceInstaller1 = new ServiceInstaller();

// The services run under the system account.

processInstaller.Account = ServiceAccount.LocalSystem;

// The services are started manually.

serviceInstaller1.StartType = ServiceStartMode.Manual;

// ServiceName must equal those on ServiceBase derived classes.

serviceInstaller1.ServiceName = "WindowsService1";

// Add installers to collection. Order is not important.

Installers.Add(serviceInstaller1);

Installers.Add(processInstaller);

}

// Event handler for 'Committing' event.

private void MyInstaller_Committing(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committing Event occured.");

Console.WriteLine("");

}

// Event handler for 'Committed' event.

private void MyInstaller_Committed(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committed Event occured.");

Console.WriteLine("");

}

// Override the 'Install' method.

public override void Install(IDictionary savedState)

{

base.Install(savedState);

}

// Override the 'Commit' method.

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

// Override the 'Rollback' method.

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

}
[RunInstaller(true)]

public class Service1 : System.ServiceProcess.ServiceBase

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Service1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

// The main entry point for the process

static void Main()

{

System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add

// another service to this process, change the following line to

// create a second service object. For example,

//

// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(),
new MySecondUserService()};

//

ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

this.ServiceName = "WindowsService1";

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

/// <summary>

/// Set things in motion so your service can do its work.

/// </summary>

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

}
/// <summary>

/// Stop this service.

/// </summary>

protected override void OnStop()

{

// TODO: Add code here to perform any tear-down necessary to stop your
service.

}

}

}

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If I had to guess, I’d say that when you are trying to install the service
you are typing:

installutil.exe windowsservice1

not:

installutil.exe windowsservice1.exe

I say that because I had no problem building and installing this service,
and only when I dropped the .exe from the installation line did I get the
exception you did.

Brendan
"Fan Wang" wrote:
Hi All,

I wrote a windows service with C# as below. But I can't install it with
installutil.exe. I got an error message "
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice1, or
one of its dependencies, was not found.. "
I am new to C# environment. Any idea any clue will be appreciated. Thanks

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.Configuration.Install;

namespace WindowsService1

{

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]

public class MyProjectInstaller: Installer

{

private ServiceInstaller serviceInstaller1;

private ServiceProcessInstaller processInstaller;

public MyProjectInstaller() :base()

{

// Attach the 'Committed' event.

this.Committed += new InstallEventHandler(MyInstaller_Committed);

// Attach the 'Committing' event.

this.Committing += new InstallEventHandler(MyInstaller_Committing);

// Instantiate installers for process and services.

processInstaller = new ServiceProcessInstaller();

serviceInstaller1 = new ServiceInstaller();

// The services run under the system account.

processInstaller.Account = ServiceAccount.LocalSystem;

// The services are started manually.

serviceInstaller1.StartType = ServiceStartMode.Manual;

// ServiceName must equal those on ServiceBase derived classes.

serviceInstaller1.ServiceName = "WindowsService1";

// Add installers to collection. Order is not important.

Installers.Add(serviceInstaller1);

Installers.Add(processInstaller);

}

// Event handler for 'Committing' event.

private void MyInstaller_Committing(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committing Event occured.");

Console.WriteLine("");

}

// Event handler for 'Committed' event.

private void MyInstaller_Committed(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committed Event occured.");

Console.WriteLine("");

}

// Override the 'Install' method.

public override void Install(IDictionary savedState)

{

base.Install(savedState);

}

// Override the 'Commit' method.

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

// Override the 'Rollback' method.

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

}
[RunInstaller(true)]

public class Service1 : System.ServiceProcess.ServiceBase

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Service1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

// The main entry point for the process

static void Main()

{

System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add

// another service to this process, change the following line to

// create a second service object. For example,

//

// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(),
new MySecondUserService()};

//

ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

this.ServiceName = "WindowsService1";

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

/// <summary>

/// Set things in motion so your service can do its work.

/// </summary>

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

}
/// <summary>

/// Stop this service.

/// </summary>

protected override void OnStop()

{

// TODO: Add code here to perform any tear-down necessary to stop your
service.

}

}

}


Nov 17 '05 #2

P: n/a
Thanks a lot. It is exactly as you said.

FAN

"Brendan Grant" <gr****@NOSPAMdahat.com> wrote in message
news:18**********************************@microsof t.com...
If I had to guess, I'd say that when you are trying to install the service
you are typing:

installutil.exe windowsservice1

not:

installutil.exe windowsservice1.exe

I say that because I had no problem building and installing this service,
and only when I dropped the .exe from the installation line did I get the
exception you did.

Brendan
"Fan Wang" wrote:
Hi All,

I wrote a windows service with C# as below. But I can't install it with
installutil.exe. I got an error message "
Exception occurred while initializing the installation:
System.IO.FileNotFoundException: File or assembly name windowsservice1, or one of its dependencies, was not found.. "
I am new to C# environment. Any idea any clue will be appreciated. Thanks
using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.ServiceProcess;

using System.Configuration.Install;

namespace WindowsService1

{

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]

public class MyProjectInstaller: Installer

{

private ServiceInstaller serviceInstaller1;

private ServiceProcessInstaller processInstaller;

public MyProjectInstaller() :base()

{

// Attach the 'Committed' event.

this.Committed += new InstallEventHandler(MyInstaller_Committed);

// Attach the 'Committing' event.

this.Committing += new InstallEventHandler(MyInstaller_Committing);

// Instantiate installers for process and services.

processInstaller = new ServiceProcessInstaller();

serviceInstaller1 = new ServiceInstaller();

// The services run under the system account.

processInstaller.Account = ServiceAccount.LocalSystem;

// The services are started manually.

serviceInstaller1.StartType = ServiceStartMode.Manual;

// ServiceName must equal those on ServiceBase derived classes.

serviceInstaller1.ServiceName = "WindowsService1";

// Add installers to collection. Order is not important.

Installers.Add(serviceInstaller1);

Installers.Add(processInstaller);

}

// Event handler for 'Committing' event.

private void MyInstaller_Committing(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committing Event occured.");

Console.WriteLine("");

}

// Event handler for 'Committed' event.

private void MyInstaller_Committed(object sender, InstallEventArgs e)

{

Console.WriteLine("");

Console.WriteLine("Committed Event occured.");

Console.WriteLine("");

}

// Override the 'Install' method.

public override void Install(IDictionary savedState)

{

base.Install(savedState);

}

// Override the 'Commit' method.

public override void Commit(IDictionary savedState)

{

base.Commit(savedState);

}

// Override the 'Rollback' method.

public override void Rollback(IDictionary savedState)

{

base.Rollback(savedState);

}

}
[RunInstaller(true)]

public class Service1 : System.ServiceProcess.ServiceBase

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public Service1()

{

// This call is required by the Windows.Forms Component Designer.

InitializeComponent();

// TODO: Add any initialization after the InitComponent call

}

// The main entry point for the process

static void Main()

{

System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add

// another service to this process, change the following line to

// create a second service object. For example,

//

// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};

//

ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);

}

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

this.ServiceName = "WindowsService1";

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

/// <summary>

/// Set things in motion so your service can do its work.

/// </summary>

protected override void OnStart(string[] args)

{

// TODO: Add code here to start your service.

}
/// <summary>

/// Stop this service.

/// </summary>

protected override void OnStop()

{

// TODO: Add code here to perform any tear-down necessary to stop your
service.

}

}

}


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.