[Mono-list] ConfigurationManager.OpenMappedExeConfiguration Problems

madrang j859 at hotmail.com
Fri Sep 23 07:17:25 EDT 2011


Hi,

It seams that ConfigurationManager.OpenMappedExeConfiguration should open
all the needed config files and will allow settings overrides. When i use
ConfigurationUserLevel.None, Machine and Exe files are opened. But when im
using ConfigurationUserLevel.PerUserRoamingAndLocal it should open Machine,
Exe, Roaming User and Local User but all settings or sections in the Exe
config are missing.

I know that the ExeConfigFile is not loaded at all cause even if i add lines
that will throw an error when parsed, mono will not throw any exception.

In the Mono-2.10.2 source it seams that the file is not loaded, but on all
MSDN/CodeProject article i can read it seams that it should be loaded.

To test i only create 4 files and load those using the following code.

This code for me throw "System.NullReferenceException: Object reference not
set to an instance of an object" on the line
"Console.WriteLine(AppSettings.Settings["ExeTest"].Value);"
if i comment the line it works.
Using ConfigurationUserLevel.None it give the same exception but on the line
"Console.WriteLine(AppSettings.Settings["RoamingTest"].Value);"
That is normal since RoamingTest is defined in the roaming file that is not
loaded using ConfigurationUserLevel.None

I hope someone can help me understand why this is happening.
Thx, Madrang

Configuration conf;
AppSettingsSection AppSettings;

var fmap = new ExeConfigurationFileMap();
//Fix the paths before running.
fmap.MachineConfigFilename = @"PATH_TO_MACHINE_FILE";
fmap.ExeConfigFilename = @"PATH_TO_EXE_FILE";
fmap.RoamingUserConfigFilename = @"PATH_TO_ROAMING_FILE";
fmap.LocalUserConfigFilename = @"PATH_TO_LOCAL_FILE";

//conf = ConfigurationManager.OpenMappedExeConfiguration(fmap,
ConfigurationUserLevel.None);
conf = ConfigurationManager.OpenMappedExeConfiguration(fmap,
ConfigurationUserLevel.PerUserRoamingAndLocal);

AppSettings = (AppSettingsSection)conf.GetSection("appSettings");

Console.WriteLine(AppSettings.Settings["MachineTest"].Value);
Console.WriteLine(AppSettings.Settings["ExeTest"].Value);
Console.WriteLine(AppSettings.Settings["RoamingTest"].Value);
Console.WriteLine(AppSettings.Settings["LocalTest"].Value);

--
View this message in context: http://mono.1490590.n4.nabble.com/ConfigurationManager-OpenMappedExeConfiguration-Problems-tp3836500p3836500.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list