繁体   English   中英

Windows服务错误:SavedState词典不包含预期值,并且可能已损坏

[英]Windows service error: the savedState dictionary does not contain the expected values and might have been corrupted

我正在尝试使用一个EXE文件创建多个服务。

我添加了一个安装程序类:

[RunInstaller(true)]
public partial class POCInstall : System.Configuration.Install.Installer
{
    private ServiceProcessInstaller m_ServiceProcess;
    private ServiceInstaller m_ServiceInstaller;
    public POCInstall()
    {
        InitializeComponent();

        m_ServiceProcess = new ServiceProcessInstaller();
        m_ServiceProcess.Account = ServiceAccount.NetworkService;
        m_ServiceProcess.Username = null;
        m_ServiceProcess.Password = null;

        m_ServiceInstaller = new ServiceInstaller();
        m_ServiceInstaller.BeforeInstall += new InstallEventHandler(onBeforeInstall);
        m_ServiceInstaller.BeforeUninstall += new InstallEventHandler(onBeforeUninstall);
        m_ServiceInstaller.BeforeRollback += new InstallEventHandler(onBeforRollback);
        m_ServiceInstaller.ServiceName = "POCService";
        this.Installers.Add(m_ServiceProcess);
        this.Installers.Add(m_ServiceInstaller);
    }

    private void onBeforRollback(object sender, InstallEventArgs e)
    {
        string serviceName = ConfigurationManager.AppSettings["ServiceName"];
        string serviceDsiaply = ConfigurationManager.AppSettings["ServiceDsiaply"];
        m_ServiceInstaller.ServiceName = serviceName;
        m_ServiceInstaller.DisplayName = serviceDsiaply;
    }

    private void onBeforeUninstall(object sender, InstallEventArgs e)
    {
        string serviceName = ConfigurationManager.AppSettings["ServiceName"];
        string serviceDsiaply = ConfigurationManager.AppSettings["ServiceDsiaply"];
        m_ServiceInstaller.ServiceName = serviceName;
        m_ServiceInstaller.DisplayName = serviceDsiaply;
    }

    private void onBeforeInstall(object sender, InstallEventArgs e)
    {
        string serviceName = ConfigurationManager.AppSettings["ServiceName"];
        string serviceDsiaply = ConfigurationManager.AppSettings["ServiceDsiaply"];
        m_ServiceInstaller.ServiceName = serviceName;
        m_ServiceInstaller.DisplayName = serviceDsiaply;
    }

}

如您所见,我从应用程序配置文件中获取服务名称和参数:

 <add key="ServiceName" value="POCService1"/>
 <add key="ServiceDsiaply" value="POC Service 1"/>

服务类为空,并且只有空的onStart和OnStop方法。

public partial class POCService : ServiceBase
{
    public POCService()
    {
        this.ServiceName = "POCService";
        InitializeComponent();
    }

    protected override void OnStart(string[] args)
    {
    }

    protected override void OnStop()
    {
    }
}

当我使用命令行执行安装时, %SystemRoot%\\Microsoft.NET\\Framework\\v4.0.30319\\InstallUtil.exe ServicePOC.exe

我得到错误:

An exception occurred during the Rollback phase of the System.ServiceProcess.ServiceInstaller installer. System.ArgumentException: The savedState dictionary does not contain the expected values and might have been corrupted.

实现一个空的public override void Commit(IDictionary savedState)方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM