I have some problems with this, but I finally found the answer.
When the configuration file looks like this:
<configuration> <appSettings file="appsettings.config"/> </configuration>
The above code works correctly:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var file = config.AppSettings.File;
But when the configuration file (it works the same as above, but the syntax is different):
<configuration> <appSettings configSource="appsettings.config"/> </configuration>
I should use the following:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var file = config.AppSettings.SectionInformation.ConfigSource;
Therefore, I have to check if config.AppSettings.SectionInformation.ConfigSource and config.AppSettings.File are not an empty string and check that it is correct.
source share