Reputation: 103
I have wrote a Windows Service and I have a admin panel which I can configure this service from a web page. In order to this I am using a database. So basically what I am doing is I change the values from the db and the service reads it and it changes its execution time.. etc.
My problem is in my development server everything works fine. When I install my service and upload the web page to the production server I am getting this error
The type or namespace name 'ServiceController' could not be found (are you missing a using directive or an assembly reference?)
It is giving this error in my web page. I have checked the service it is installed and works fine but when I am trying to go to the configuration page for the service it hrows this exception. In my project i see that I have using System.ServiceProcess;
is added in the top and when I build my solution this dll reference error doesnt show up. Also in the designer it seems like it is already imported:
<@ Import Namespace="System.ServiceProcess">;
What might be the problem? Can it be a 32-bit / 64-bit issue? ( I know it doesnt make sense but any help will be appreciated)
ServiceController agService = new ServiceController("Buddy Service");
while (agService.Status == ServiceControllerStatus.Running)
{
lblServiceStatus.Text = "Running";
lblServiceStatus.ForeColor = Color.LimeGreen;
btnStopService.Enabled = true;
btnStartService.Enabled = false;
break;
}
It throws the exception on the line
ServiceController agService = new ServiceController("Buddy Service");
I have made sure that "Buddy Service" is in the Services list and it does.
Upvotes: 2
Views: 3481
Reputation: 44971
It sounds like you have the assembly referenced correctly.
Try changing this line:
ServiceController agService = new ServiceController("Buddy Service");
to this:
var agService = new System.ServiceProcess.ServiceController("Buddy Service");
If this works, you will probably also need to change this line:
while (agService.Status == ServiceControllerStatus.Running)
to this:
while (agService.Status == System.ServiceProcess.ServiceControllerStatus.Running)
Upvotes: 2
Reputation: 2206
be sure you added the System.ServiceProcess in your references list than the user list:
Upvotes: 3