I've been fighting with an ASP.NET 1 conversion to ASP.NET 2 where for some unknown reason, the Global.asax code is no longer being run. No matter what I do, including making a Global class or even embedding the code into the asax file, the Application_Start is not being invoked when the app starts. No matter though.
What I am embarassed about though is a simple mistake:
Guess what value "Foo.KEY" has after you call Foo.Instance? Eight hours later, I finally realized why KEY is always null and the real fix is just to do the following:
When Foo.Instance is called, the Foo static instance was being created, and the ctor was being invoked which set the value of KEY. Then the next initialization occured where the KEY = null statement was executed, and thus the KEY value was clobbered back to null.
Rookie.
What I am embarassed about though is a simple mistake:
public class Foo
{
private static Foo _Instance = new Foo();
private static KEY = null;
private Foo()
{
KEY = ConfigurationSettings.AppSettings["MyKeyValue"];
}
public static Foo Instance() { return(_Instance); }
}
Guess what value "Foo.KEY" has after you call Foo.Instance? Eight hours later, I finally realized why KEY is always null and the real fix is just to do the following:
public class Foo
{
private static KEY = null;
private static Foo _Instance = new Foo();
private Foo()
{
KEY = ConfigurationSettings.AppSettings["MyKeyValue"];
}
public static Foo Instance() { return(_Instance); }
}
When Foo.Instance is called, the Foo static instance was being created, and the ctor was being invoked which set the value of KEY. Then the next initialization occured where the KEY = null statement was executed, and thus the KEY value was clobbered back to null.
Rookie.