Mono not reading values from my app.config?

2019-05-01 15:34发布

问题:

I have a standard app.config for a .NET 4.0 Console application created by Visual Studio 2010 when adding settings in the project Settings tab as described on MSDN here: Application Settiings.

If I update a setting value in the resulting MyAsseblyName.exe.config file in the same directory then run the exe I see this in code by going:

Properties.Settings.Default.MySetting;

However, if I do the same (with the same build and same files) running Mono 3.2.8 on Ubuntu 14.04 using the above line gives me the default value specified on project Settings tab instead of the updated value in the MyAsseblyName.exe.config file.

What do I have to do to make mono use my app.config like .NET does so values are read from file if they are there?

Workaround

For anyone else coming across this issue I was able to workaround it by moving my settings in my app.config into the old-school <appSettings> element from <userSettings> or <applicationSettings> created by the project designer. Then you can use:

var myValue = ConfigurationManager.AppSettings["MyKey"];

See http://msdn.microsoft.com/en-AU/library/system.configuration.configurationmanager.appsettings(v=vs.100).aspx