The following file displays the file and then opens it as a System.Configuration variable:
string FilePath = System.Reflection.Assembly.GetAssembly(typeof(EncryptDecryptViewModel)).Location FilePath += @".config"; var ConfigFileMap = new ExeConfigurationFileMap(); ConfigFileMap.ExeConfigFilename = FilePath; Configuration LocalConfigurationManager = ConfigurationManager.OpenMappedExeConfiguration(ConfigFileMap, ConfigurationUserLevel.None);
Now you can extract values ββfrom the assembly configuration file in the same way as through the configuration manager, however you should be a little more explicit in your requests.
When using System.Configuration.ConfigurationManager, the following value will be valid and return a value:
string s = System.Configuration.ConfigurationManager.AppSettings["SomeSetting"];
However, when using the LocalConfigurationManager configuration parameter (from the above code), a call, such as a regular ConfigurationManager call, for example:
string s = LocalConfigurationManager.AppSettings["ConfigurationSections"];
When you try to run the code, you get the following error:
'System.Configuration.ConfigurationElement.this [System.Configuration.ConfigurationProperty]' is unavailable due to its level of protection
This is because in the ConfigurationManager, the AppSettings property is NameValueCollection. In the configuration variable, AppSettings is actually a System.Configuration.AppSettingsSection that contains the Parameters property, which is KeyValueConfigurationCollection, so the call will look like this to access the property:
string s = LocalConfigurationManager.AppSettings.Settings["SomeSetting"].Value;
The section "String join strings" uses the following syntax
string ConnectionString = LocalConfigurationManager.ConnectionStrings.ConnectionStrings["connectionStringName"].ConnectionString;