I was trying to utilise the ConfigurationManager to read a config file, but it seems to return, but the data is not the data in the .config file (in particular the ConfigurationManger is reporting no applicationSettings or appSettings and does have a connectionString value; though the configuration file itself has appSettings and no connectionString) I've tried both the OpenExeConfiguration and the OpenMappedExeConfiguration methods.
If I use XmlDocument to the same configuration file though I can see the correct nodes and appSettings.
I'm using just a basic .config file generated via a console application creation of settings.
It almost looks like the ConfigurationManager is not reading the data from the configuration file provided. The connection string provided in the configuration manager is "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" which seems generic and not in any of the code or .config file
Configuration Manager Code
var configurationManager = ConfigurationManager.OpenExeConfiguration(@"D:\temp\my.config");
I've also tried with the following to deal with the addition of the .config; it is odd that if I just use "D:\temp\my" it errors with a message about invalid.
var configurationManager = ConfigurationManager.OpenExeConfiguration(@"D:\temp\my.config.config");
Configuration Manager with Mapping
ExeConfigurationFileMap map = new ExeConfigurationFileMap { ExeConfigFilename = @"D:\temp\my.config" };
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
Xml Code
XmlDocument configurationDocument = new XmlDocument();
configurationDocument.Load(@"D:\temp\my.config");