Why my C# does not have System.ServiceProcess Library?

不羁的心 提交于 2019-12-19 05:08:26

问题


This is the code. I just wanna test the library of System.ServiceProcess library.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("hi");
            var srv = new ServiceController("MyService");
            Console.WriteLine("MyService Status {0}", srv.Status);
            if (srv.Status != ServiceControllerStatus.Running)
                srv.Start();
            System.Threading.Thread.Sleep(1000000);
        }
    }
}

However, when I run the C# code, its says:

Error 1 The type or namespace name 'ServiceProcess' does not exist in the namespace 'System' (are you missing an assembly reference?)

What went wrong?


回答1:


System.ServiceProcess namespace belongs on System.ServiceProcess.dll and it doesn't added as a reference by default.

For this, in the solution window, right click on "References" and choose "Add Reference.." Go to the .NET tab, and double click on System.ServiceProcess.dll.

This assembly is probably in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 folder.




回答2:


You need to add a reference to the corresponding .dll as well.

Right click on the project -> Add Reference -> Assemblies -> Framework -> System.ServiceProcess




回答3:


you should add this from framework list Right click on the project -> Add Reference -> search under "Assemblies" -> select->OK



来源:https://stackoverflow.com/questions/19763527/why-my-c-sharp-does-not-have-system-serviceprocess-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!