Search code examples
c#windows-services.net-6.0servicecontroller

Error when attempting to use System.ServiceProcess class to check status of Worker/Windows Service in .NET 6 C# Form application


I have created a Worker Service and a Windows Form Application, the Form application functions as a way to check if the service is installer or not, if it's running or not running.

I attempted using the System.ServiceProcess.ServiceController class but when i'm using ServiceController i get the following error:

System.PlatformNotSupportedException: ServiceController enables manipulating and accessing Windows services and it is not applicable for other operating systems. at System.ServiceProcess.ServiceController..ctor(String name)

The error is reacting to the following code

        return ServiceController.GetServices().Any(ServiceController => 
        ServiceController.ServiceName.Equals(ServiceName));

I'm struggling to figure out how to solve this error, I'm still a beginner at C# and .NET so any suggestions would be appreciated. I have also attempted to install the System.ServiceProcess.ServiceController NuGet package but it didn't help.

Any suggestions?


Solution

  • The solution was ServiceController.dll was missing, after adding into my app project file also removing the nuget package System.ServiceProcess.ServiceController it seemed to solve this issue, i assumed that adding the nuget package was enough when it comes to the .dll file.