Tanuj Wadhwa
Tanuj Wadhwa

Reputation: 2045

Accessing Values from configSections of App.Config of different application

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

Upvotes: 0

Views: 855

Answers (1)

krlzlx
krlzlx

Reputation: 5832

Try this:

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

Screenshot: enter image description here

Upvotes: 1

Related Questions