从不同应用程序

时间:2015-10-12 10:53:00

标签: c# .net app-config

我正在尝试使用以下代码从其他应用程序中读取configSections App.Configpublic string ReadValue(string FileName,string Key) { //File name is the path of the App.Config from a different application ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = FileName; Configuration config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); var section =config.GetSection("dev") as AppSettingsSection ; return section[Key]; } 文件中的值:

System.Configuration.ConfigurationElement.this[System.Configuration.ConfigurationProperty]' is inaccessible due to its protection level

我收到错误limit

如何使此代码正常工作? 感谢

1 个答案:

答案 0 :(得分:1)

试试这个:

  • 双击Settings.settings文件。
  • 将您的访问修饰符更改为:公开

截图: enter image description here