Friday 4 March 2011

Eager Beavers at M$

using System.Configuration;


System.Configuration.Configuration config =
   ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);


config.AppSettings.Settings["testkey"].Value = "testvalue";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

Test this C# code on a standard C# project in Visual Studio. It's simply a few statements to write in app.config.
It won't compile, even if you have all the right using statements, and even if other System.Configuration objects are recognized. The errors  usually go like:


Error 1 The type or namespace name 'Configuration' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?) d:\work\fbtest3\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs 22 34 WindowsFormsApplication2

There is a simple solution, which you won't you usually find looking around. Add a reference to system.configuration to your project references. I first found this quirk in VS 2005 a few years ago. Today, after fuggedabout'ing it and spending half an hour wondering, I've verified it is still present in VS2008 and VS2010. 

Those microserfs....

No comments:

Post a Comment