0

I am trying to read values from the different configSections of App.Config file from a different application using this code:

public 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];


         }

I am getting error as System.Configuration.ConfigurationElement.this[System.Configuration.ConfigurationProperty]' is inaccessible due to its protection level

How do I get this code working? Thanks

Tanuj Wadhwa
  • 2,025
  • 9
  • 35
  • 57
  • Possible duplicate of [this](http://stackoverflow.com/questions/8587614/configurationproperty-is-inaccessible-due-to-its-protection-level) – Rahul Jha Oct 12 '15 at 10:58
  • i dont think its the same thing, because this code tries to access the app.config file from a file path and therefore cannot use OpenExeConfiguration – Tanuj Wadhwa Oct 12 '15 at 11:22

1 Answers1

1

Try this:

  • Double click on your Settings.settings file.
  • Change your Access Modifier to: Public

Screenshot: enter image description here

krlzlx
  • 5,752
  • 14
  • 47
  • 55