0

我有被檢索上打開我收到以下錯誤exeConfiguration從Visual Studio安裝project.Now參數的安裝程序類..在加載配置文件中獲取錯誤,參數無效

Error 1001:An error occurred loading a configuration file. 
The parameter 'exePath' is  invalid. 
Parameter name:exepath-->The Parameter 'exePath' is invalid. 
Parameter name:exePath 

這裏是我的Installer.cs代碼..

public override void Install(System.Collections.IDictionary stateSaver) 
    { 

     base.Install(stateSaver); 

     string targetDirectory = Context.Parameters["targetdir"]; 

     string param1 = Context.Parameters["Param1"]; 

     string param2 = Context.Parameters["Param2"]; 

     string param3 = Context.Parameters["Param3"]; 

     string exePath = string.Format("{0}TechSoft CallBill.exe", targetDirectory); 

     Configuration config = ConfigurationManager.OpenExeConfiguration(exePath); 

     config.AppSettings.Settings["Param1"].Value = param1; 

     config.AppSettings.Settings["Param2"].Value = param2; 

     config.AppSettings.Settings["Param3"].Value = param3; 

     config.Save(); 
    } 

enter image description here

請幫我弄清楚這個錯誤,因爲我無法弄清楚。 任何建議熱烈歡迎。 在此先感謝

+1

你試圖加載配置屬於不同的項目?或者它屬於安裝程序類項目? – Kurubaran

+0

@AccessDenied非常感謝你sir.Config屬於安裝程序類project.Here我附加項目classpath圖像。 – Adi

+0

@AccessDenied請先生告訴我我哪裏出錯了? – Adi

回答

1

如果Config文件屬於同一個項目,那麼試試這個,如果配置文件屬於同一個項目,那麼你不必使用配置文件路徑。

Configuration config= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 

config.AppSettings.Settings["Param1"].Value = param1; 

config.AppSettings.Settings["Param2"].Value = param2; 

config.AppSettings.Settings["Param3"].Value = param3; 

//Save only the modified section of the config 
config.Save(ConfigurationSaveMode.Modified); 

//Refresh the appSettings section to reflect updated configurations 
ConfigurationManager.RefreshSection(Constants.AppSettingsNode); 
+0

先生什麼是Constants.AppSettingsNode中的常量,因爲我在常量關鍵字 – Adi

+0

中出現錯誤我試過這段代碼,但仍然存在問題persists.WindowsService1正在成功安裝,但在TechSoft CallBill中存在問題。請參閱我的項目類路徑圖片在我的文章 – Adi

+0

@Adi常量值應該是「appSettings」 – Kurubaran

相關問題