【问题标题】:Getting error in loading Configuration file,Parameter is not valid加载配置文件时出错,参数无效
【发布时间】:2013-12-20 06:34:59
【问题描述】:

我有一个安装程序类,它正在从 Visual Studio 安装项目中检索参数。现在打开 exeConfiguration 我收到以下错误..

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();
    }

请帮我解决这个错误,因为我无法弄清楚。 任何建议都受到热烈欢迎。 在此先感谢

【问题讨论】:

  • 您是否尝试加载属于不同项目的配置?还是属于安装程序类项目?
  • @AccessDenied 非常感谢先生。配置属于安装程序类项目。这里我附上项目类路径图像。
  • @AccessDenied 请先生告诉我哪里出错了?
  • 检查我的答案,试试那个代码。它应该可以工作。

标签: c# configuration installation string-formatting configurationmanager


【解决方案1】:

如果配置文件属于同一个项目,那么试试这个,如果配置文件属于同一个项目,那么你不必使用配置文件路径。

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);

【讨论】:

  • 先生,Constants.AppSettingsNode 中的常量是什么,因为我在常量关键字中遇到错误
  • 我尝试了这段代码,但问题仍然存在。WindowsService1 安装成功,但 TechSoft CallBill 中存在问题。请在我的帖子中查看我的项目类路径图像
  • @Adi 常量值应为“appSettings”
  • ConfigurationManager.RefreshSection(appSettings.AppSettingsNode);此行为“appSettings”提供红色标记
  • 你在哪个项目中放置了上述逻辑?天软?为什么你有两个安装程序类? TechSoft 和 WindowsService1 中的一个?
猜你喜欢
  • 2013-08-29
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
  • 1970-01-01
  • 1970-01-01
  • 2018-06-25
  • 2022-08-23
  • 1970-01-01
相关资源
最近更新 更多