为什么我的C#没有System.ServiceProcess库?
这是代码。我只想测试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
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中)