Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.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# Windows服务赢得';t安装";“未找到文件异常”;_C#_Visual Studio 2010_Service_Windows Services - Fatal编程技术网

C# Windows服务赢得';t安装";“未找到文件异常”;

C# Windows服务赢得';t安装";“未找到文件异常”;,c#,visual-studio-2010,service,windows-services,C#,Visual Studio 2010,Service,Windows Services,当我尝试安装服务时,出现以下错误: Exception Occured while initializing the installation: System.IO.FileNotFoundException: Could Not load file or assembly 'file:///C:\...\bin\Debug\OrionRAService' or one of its dependancies. The System cannot find the file specified

当我尝试安装服务时,出现以下错误:

Exception Occured while initializing the installation:
System.IO.FileNotFoundException: Could Not load file or assembly 'file:///C:\...\bin\Debug\OrionRAService' or one of its dependancies. 
The System cannot find the file specified.
我正在使用visualstudio命令行进行安装,并且我位于正确的目录中。我知道该文件存在,因为我可以在文件浏览器中看到它。 下面是我的服务代码(至少是服务的部分,任何遗漏的都是计算和内容):

使用系统;
使用System.Runtime.Serialization;
使用System.Collections.Generic;
使用系统组件模型;
使用System.ServiceModel;
使用System.ServiceProcess;
使用系统配置;
使用System.Configuration.Install;
使用System.IO;
使用System.Xml;
使用System.Xml.Linq;
名称空间OrionRAService
{
//定义服务合同。
[ServiceContract(命名空间=”http://OrionRAService")]
公共接口计算器
{
[经营合同]
列出CollectAllProfiles();
[经营合同]
布尔视觉(剖面图P);
[经营合同]
无效更改配置文件活动(配置文件p,布尔为活动);
[经营合同]
void ChangeDaysToKeepData(int DayCount);
//[经营合同]
//作废集合活动配置文件(日期时间开始、日期时间结束);
}
[数据合同]
公共班级简介
{
//... ... ...
}
公共类计算器服务:ICalculator
{    
//从ICalculator实现所有方法
}
公共类计算器WindowsService:ServiceBase
{
//... ... ...
公共服务主机mHost=null;
//... ... ...
公共计算器WindowsService()
{
//命名Windows服务
ServiceName=“OrionRAService”;
}
公共静态void Main()
{
运行(新计算器WindowsService());
}
启动时受保护的覆盖无效(字符串[]args)
{
if(mHost!=null)
{
mHost.Close();
}
mHost=新服务主机(typeof(CalculatorService),新Uri(“net。pipe://localhost"));
mHost.AddServiceEndpoint(typeof(ICalculator),新的NetNamedPipeBinding(),“MyServiceAddress”);
mHost.Open();
//... ... ...
}
受保护的覆盖void OnStop()
{
if(mHost!=null)
{
mHost.Close();
mHost=null;
}
}
}
//提供ProjectInstaller类,该类允许
//要由Installutil.exe工具安装的服务
[运行安装程序(true)]
公共类项目安装程序:安装程序
{
私有ServiceProcessInstaller进程;
私人服务安装服务;
公共项目安装程序()
{
进程=新的ServiceProcessInstaller();
process.Account=servicecomport.LocalSystem;
服务=新的ServiceInstaller();
service.ServiceName=“OrionRAService”;
安装程序。添加(进程);
安装程序。添加(服务);
}
}
}
以下是App.Config:



您是否尝试将二进制文件移动到另一个目录,然后尝试从该位置注册为服务?能否发布您使用的命令?C:\…\bin\Debug>install.exe OrionRAService.exe我认为您缺少的是依赖项,而不是实际的主服务程序集。一个接一个地检查所有引用,确保每个引用都在安装文件夹或GAC中。确保它们完全相同的程序集版本也很重要。
using System;
using System.Runtime.Serialization;
using System.Collections.Generic;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceProcess;
using System.Configuration;
using System.Configuration.Install;
using System.IO;
using System.Xml;
using System.Xml.Linq;

namespace OrionRAService
{
   // Define a service contract.
    [ServiceContract(Namespace = "http://OrionRAService")]
    public interface ICalculator
    {
        [OperationContract]
        List<Profile> CollectAllProfiles();
        [OperationContract]
        bool IsItActive(Profile P);
        [OperationContract]
        void ChangeProfileActivity(Profile p,bool isActive);
        [OperationContract]
        void ChangeDaysToKeepData(int DayCount);
        //[OperationContract]
        //void CollectOnActiveProfiles(DateTime startTake, DateTime endTake);
    }
    [DataContract]
    public class Profile
    {
        //... ... ...
    }
    public class CalculatorService : ICalculator
    {    
        //implementation of all methods from ICalculator
    }
    public class CalculatorWindowsService : ServiceBase
    {
        //... ... ...
        public ServiceHost mHost = null;
        //... ... ...
        public CalculatorWindowsService()
        {
            // Name the Windows Service
            ServiceName = "OrionRAService";
        }
        public static void Main()
        {
            ServiceBase.Run(new CalculatorWindowsService());
        }
        protected override void OnStart(string[] args)
        {
            if (mHost != null)
            {
                mHost.Close();
            }
            mHost = new ServiceHost(typeof(CalculatorService), new Uri("net.pipe://localhost"));
            mHost.AddServiceEndpoint(typeof(ICalculator), new NetNamedPipeBinding(), "MyServiceAddress");
            mHost.Open();
            //... ... ...
        }
        protected override void OnStop()
        {
            if (mHost != null)
            {
                mHost.Close();
                mHost = null;
            }
        }
    }
    // Provide the ProjectInstaller class which allows 
    // the service to be installed by the Installutil.exe tool
    [RunInstaller(true)]
    public class ProjectInstaller : Installer
    {
        private ServiceProcessInstaller process;
        private ServiceInstaller service;

        public ProjectInstaller()
        {
            process = new ServiceProcessInstaller();
            process.Account = ServiceAccount.LocalSystem;
            service = new ServiceInstaller();
            service.ServiceName = "OrionRAService";
            Installers.Add(process);
            Installers.Add(service);
        }
    }
}