Why would this line throw exception for type initializer failed?
- by Jaggu
I had a class:
public class Constant
{
public static string ConnString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
}
which would throw exception on LIVE: Type initialize failed for Constant ctor
If I change the class to:
public class Constant
{
public static string ConnString
{
get
{
return ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
}
}
}
it works. I wasted 2 hours behind this but I still don't know why would this happen. Any ideas?
Note: The 1st class used to work on DEV environment but not on LIVE. The 2nd class works on DEV and also on Production.
I am using VS2010 on production and Asp.Net 4.0 Website project.
I am totally amazed by this inconsistency to say the least!
Edit: This class was in App_Code folder.