Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的C#没有System.ServiceProcess库?_C#_.net_Service_Assembly References - Fatal编程技术网

为什么我的C#没有System.ServiceProcess库?

为什么我的C#没有System.ServiceProcess库?,c#,.net,service,assembly-references,C#,.net,Service,Assembly References,这是代码。我只想测试System.ServiceProcess库的库 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.ServiceProcess; namespace ConsoleApplication1 { class Program { stati

这是代码。我只想测试System.ServiceProcess库的库

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);
        }
    }
}
但是,当我运行C代码时,它会说:

错误1中不存在类型或命名空间名称“ServiceProcess” 命名空间“System”(是否缺少程序集引用?)


出了什么问题?

您还需要添加对相应.dll的引用

右键单击项目->添加引用->程序集->框架->系统.ServiceProcess

命名空间属于
系统.ServiceProcess.dll
,默认情况下它不会作为引用添加

为此,在解决方案窗口中,右键单击“引用”并选择“添加引用…”转到.NET选项卡,然后双击System.ServiceProcess.dll


此程序集可能位于
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
文件夹中。

您应该从框架列表中添加此程序集 右键单击项目->添加参考->在“装配”->选择->确定下搜索


是否缺少程序集引用?
该错误已经在引导您找到解决方案。查找,您将看到以下内容:
Assembly:System.ServiceProcess(在System.ServiceProcess.dll中)