0
Answer

Reflection and Config settings weird behavior

Art

Art

15y
3k
1

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?