S
Steve
I'm currently running into a problem, and I have no idea what to make of it.
I have a class with nested clases and static properties that I'm using
to store configuration information using a custom configuration section.
When my code accesses one of the static properties the static
constructors are fired, and the code goes in and pulls the data from the
configuration section.
In the current instance, I'm getting a connection string. The call is
made to the static property. When the code returns the property value,
it is an empty string. If I type
Config.ConnectionStrings.AuthenticatedUser in the Command Window while
debugging the proper connection string value is present.
I have tried placing multiple calls to the property in my code to see if
something wasn't be initialized properly on the first call.
Unfortunately the behavior is the same everytime. Call from code, get an
empty string. Call from the Command Window, get the expected value.
Does anyone have any idea what might be going on here? Below is the code
that I'm using.
Thanks,
Steve
public class Config {
static Config() {
object config = ConfigurationSettings.GetConfig("SystemConfig");
if (config == null) {
throw new ConfigurationException("No SystemConfig section was
specified.");
}
}
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
//Get the connection strings
string authenticatedUser = ConfigurationParser.GetAttribute(section,
"AuthenticatedUser", true);
string unauthenticatedUser =
ConfigurationParser.GetAttribute(section, "UnauthenticatedUser", true);
ConnectionStrings.SetConnectionStrings(authenticatedUser,
unauthenticatedUser);
return true;
}
internal static void Load() {}
public class ConnectionStrings {
private static string _AuthenticatedUser = "";
private static string _UnauthenticatedUser = "";
static ConnectionStrings() {
//Used to get the static Config constructor to fire.
Config.Load();
}
internal static void SetConnectionStrings(string authenticatedUser,
string unauthenticatedUser) {
_AuthenticatedUser = authenticatedUser;
_UnauthenticatedUser = unauthenticatedUser;
}
public static string AuthenticatedUser {
get {return _AuthenticatedUser;}
}
public static string UnauthenticatedUser {
get {return _UnauthenticatedUser;}
}
}
}
I have a class with nested clases and static properties that I'm using
to store configuration information using a custom configuration section.
When my code accesses one of the static properties the static
constructors are fired, and the code goes in and pulls the data from the
configuration section.
In the current instance, I'm getting a connection string. The call is
made to the static property. When the code returns the property value,
it is an empty string. If I type
Config.ConnectionStrings.AuthenticatedUser in the Command Window while
debugging the proper connection string value is present.
I have tried placing multiple calls to the property in my code to see if
something wasn't be initialized properly on the first call.
Unfortunately the behavior is the same everytime. Call from code, get an
empty string. Call from the Command Window, get the expected value.
Does anyone have any idea what might be going on here? Below is the code
that I'm using.
Thanks,
Steve
public class Config {
static Config() {
object config = ConfigurationSettings.GetConfig("SystemConfig");
if (config == null) {
throw new ConfigurationException("No SystemConfig section was
specified.");
}
}
public object Create(object parent, object configContext,
System.Xml.XmlNode section) {
//Get the connection strings
string authenticatedUser = ConfigurationParser.GetAttribute(section,
"AuthenticatedUser", true);
string unauthenticatedUser =
ConfigurationParser.GetAttribute(section, "UnauthenticatedUser", true);
ConnectionStrings.SetConnectionStrings(authenticatedUser,
unauthenticatedUser);
return true;
}
internal static void Load() {}
public class ConnectionStrings {
private static string _AuthenticatedUser = "";
private static string _UnauthenticatedUser = "";
static ConnectionStrings() {
//Used to get the static Config constructor to fire.
Config.Load();
}
internal static void SetConnectionStrings(string authenticatedUser,
string unauthenticatedUser) {
_AuthenticatedUser = authenticatedUser;
_UnauthenticatedUser = unauthenticatedUser;
}
public static string AuthenticatedUser {
get {return _AuthenticatedUser;}
}
public static string UnauthenticatedUser {
get {return _UnauthenticatedUser;}
}
}
}