session - Static Property losing its value intermittently? -


Is there anything wrong with the design, or anyone can see that static properties sometimes have their values Relaxed?

I have a class library project in which the class is AppConfig; This class is consumed by a webform project

The skeleton of the AppConfig class is as follows:.

  public class AppConfig Implements IConfigurationSectionHandler Private Const C_KEY1 = "WebConfig.Key as string 1" Private Const C_KEY2 As String = "WebConfig.Key.2" Private Const C_KEY1_DEFAULT_VALUE get string = "Key1defaultVal" string as Private Const C_KEY2_DEFAULT_VALUE = "Key2defaultVal" private mutual m_field1 string as private share m_field2 string (as in the form of share ReadOnly property ConfigValue1 publicly) ConfigValue1 = m_field1 gain share at the end end of the string as read publicly shared only property ConfigValue2 () to ConfigValue2 = m_field2 finally get property public share Uppriwartn (START) m_field1 = ReadSetting (C_KEY1, C_KEY1_DEFAULT_VALUE) m_field2 = ReadSetting (C_KEY2, C_KEY1_DEFAULT_VALUE) end sub P ublic Overloads shared function ReadSetting (ByVal Key string, ByVal DefaultValue string as dim settings as in) string as string = System.Configuration.Configu So rationManager.AppSettings nothing settings try (key) then ReadSetting = DefaultValue or ReadSetting = catch establishing ReadSetting end then = default value Create End End End Function Public Function (ByVal parent as object, object ByVal configContext as the system, byval section System.Xml.XmlNode as the object, the Implements System.Configuration.ConfigurationSectionHandler.Create dim objSettings name name as NameValueCollection Dim objHandler name NameValueSectionHandler objHandler = New NameValueSectionHandler objS Ettings = CTYPE (objHandler.Create (parent, configContext, section), NameValueCollection) return 1 ending function ending class  

static properties get ready at once, start the application Global.asax the Application_Start event

  sub Application_Start (ByVal this object, ByVal have e EventArgs early AppConfig.OnApplicationStart as) // fire as application, when () End sub  

For example,

  AppConfig.ConfigValue1 () AppConfig.ConfigValue2 ()  

In this rotation steady backing field Valid values ​​give m_field1, m_field2

Problems Sometimes these values ​​are empty string, when clearly the web. There are values ​​for config entry.

Is there something fundamentally wrong with the above design or is there any reasonable expectation that the value of static properties will be of value for the life of the application session?

I can add some debug / trace output, maybe to see what is happening. Be sure to find any exceptions.

I will also change the property returns to use the modern syntax (I'm not sure how well it is supported now)

  Change default value < / Code> 

instead:

  ReadSetting = defaultValue  

Comments