2013-08-06 3 views
1
[RunInstaller(true)] 
    public partial class ProjectInstaller : Installer 
    { 
     private ServiceInstaller m_serviceInstaller; 
     private ServiceProcessInstaller m_processInstaller; 


     public ProjectInstaller() 
     {    
      string Names= ConfigurationManager.AppSettings["Names"].ToString(); 
      System.Diagnostics.Debugger.Break(); 
      m_serviceInstaller = new System.ServiceProcess.ServiceInstaller(); 
      m_processInstaller = new System.ServiceProcess.ServiceProcessInstaller(); 
      // 
      // serviceProcessInstaller1 
      // 
      m_processInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem; 
      m_processInstaller.Password = null; 
      m_processInstaller.Username = null; 
      // 
      // serviceInstaller1 
      //  
      m_serviceInstaller.ServiceName = "Testing" + Names; 
      m_serviceInstaller.DisplayName = "Testing" + Names; 
      m_serviceInstaller.Description = "Testing" + Names; 
      // 
      // ProjectInstaller 
      // 
      this.Installers.AddRange(new System.Configuration.Install.Installer[] { 
      m_processInstaller, 
      m_serviceInstaller}); 
     } 
    } 

위와 같이 프로젝트 설치 프로그램 코드를 컴파일하면 오류가 발생하지 않지만 설치를 시도하면 System.Null 참조 예외가 발생하기 때문에 롤백이됩니다. 또한 AppConfig를 아무 문제없이 두 번 확인했습니다.ConfigurationManager.AppSettings 프로젝트 설치 관리자에서 오류가 발생했습니다.

<appSettings>  
    <add key="Names" value="BOC" /> 
    </appSettings> 

어디서 잘못 될지 알고 있습니다.

+0

그 설정 파일은 앱 실행 경로에 복사/출판 확인하시기 바랍니다 – LittleSweetSeas

+0

그래,가 –

답변

2

같은 문제가있었습니다. 기본적으로 서비스 설치 단계에서 우리는 < 프레임 워크 경로 > \ InstallUtil.exe.Config (예 : C : \ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ InstallUtil.exe.Config)를 읽는 중입니다.

해결 방법을 수동으로 권한 설정을로드하는 것입니다 :

using System.Reflection; 
... 

Configuration config = ConfigurationManager.OpenExeConfiguration(
    Assembly.GetExecutingAssembly().Location); 

KeyValueConfigurationElement element = config.AppSettings.Settings["Names"]; 

string names = null; 
if (element != null) 
    names = element.Value;