【问题标题】:c# AssemblyInstaller service install blocking access to dll filec# AssemblyInstaller 服务安装阻止访问 dll 文件
【发布时间】:2017-10-10 09:24:19
【问题描述】:

我正在使用以下代码安装服务。

string[] commandLineOptions = new string[0];
System.Configuration.Install.AssemblyInstaller installer = new System.Configuration.Install.AssemblyInstaller(path, commandLineOptions);
installer.UseNewContext = true;
installer.Install(null);
installer.Commit(null);

安装运行良好,但安装后,在尝试删除服务中包含的 dll 文件时,由于访问被拒绝,无法执行此操作。关闭应用程序后问题消失(仍然安装服务)。如何解决?

【问题讨论】:

    标签: c# dll service installation


    【解决方案1】:

    尝试在安装程序上调用Dispose() 或使用“使用”包装代码:

    using (var installer = new AssemblyInstaller(path, commandLineOptions))
    {
        installer.UseNewContext = true;
        installer.Install(null);
        installer.Commit(null);    
    }
    

    来自 MSDN 上的 AssemblyInstaller:

    Dispose() Releases all resources used by the Component.(Inherited from Component.)

    【讨论】:

      猜你喜欢
      • 2011-06-01
      • 2012-09-06
      • 2018-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多