1

Finding a custom section in a config file works when I use a path to a file, but when I pass in an exe config file map of the same thing it fails. Why?

string file = System.Reflection.Assembly.GetAssembly(typeof(PhotoComparison)).Location + ".config";

var efm = new ExeConfigurationFileMap() { ExeConfigFilename = file };
var cfm new ConfigurationFileMap(file)

//returns entry
var o2 = ConfigurationManager.OpenMappedMachineConfiguration(cfm).GetSection("presetFilters");

//returns null
var o3 = ConfigurationManager.OpenMappedMachineConfiguration(efm).GetSection("presetFilters");
Neil Walker
  • 6,400
  • 14
  • 57
  • 86

1 Answers1

0

.NET applications use a hierarchy of config files. I find this diagram describes well the situation.

The way you are using ExeConfigurationFileMap, you are setting the executable configuration file. However you are calling the method OpenMappedMachineConfiguration which should only load the machine configuration file.

I think you are not actually loading the file you want. Maybe this would work for you :

string file = "some config ...";    
// ExeConfigFilename => MachineConfigFilename
var efm = new ExeConfigurationFileMap() { MachineConfigFilename = file };  
var o3 = ConfigurationManager.OpenMappedMachineConfiguration(efm).GetSection("presetFilters");