Art

Art

  • NA
  • 1
  • 0

Reflection and Config settings weird behavior

Apr 5 2009 10:04 PM

A procedure loops thru class' properties (via reflection) and sets them to values contained in a app.config file like this

foreach (PropertyInfo property in type.GetProperties())

{

   if (ConfigurationManager.AppSettings[property.name] != null)

   {

      value = ConfigurationManager.AppSettings[property.name];

   }

}

However in two cases we've seen behaviour we can't explain. For example when property.name = "ValidState" ConfigurationManager.AppSettings[property.name] is NULL. But when I substitue property.name for "ValidState" then it works as expected. Another words:

(when property.name="ValidState")

ConfigurationManager.AppSettings[property.name] doesn't work but ConfigurationManager.AppSettings["ValidState"] works.

What could be the problem?