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.Connecti onStrings.Authe nticatedUser 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 = ConfigurationSe ttings.GetConfi g("SystemConfig ");
if (config == null) {
throw new ConfigurationEx ception("No SystemConfig section was
specified.");
}
}
public object Create(object parent, object configContext,
System.Xml.XmlN ode section) {
//Get the connection strings
string authenticatedUs er = ConfigurationPa rser.GetAttribu te(section,
"AuthenticatedU ser", true);
string unauthenticated User =
ConfigurationPa rser.GetAttribu te(section, "Unauthenticate dUser", true);
ConnectionStrin gs.SetConnectio nStrings(authen ticatedUser,
unauthenticated User);
return true;
}
internal static void Load() {}
public class ConnectionStrin gs {
private static string _AuthenticatedU ser = "";
private static string _Unauthenticate dUser = "";
static ConnectionStrin gs() {
//Used to get the static Config constructor to fire.
Config.Load();
}
internal static void SetConnectionSt rings(string authenticatedUs er,
string unauthenticated User) {
_AuthenticatedU ser = authenticatedUs er;
_Unauthenticate dUser = unauthenticated User;
}
public static string AuthenticatedUs er {
get {return _AuthenticatedU ser;}
}
public static string Unauthenticated User {
get {return _Unauthenticate dUser;}
}
}
} 4 1517
Steve,
Config.Create, which does the actual loading of the config data, is
never called by either Config or ConnectionStrin gs.
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/
Chris R. Timmons wrote: Steve,
Config.Create, which does the actual loading of the config data, is never called by either Config or ConnectionStrin gs.
Config.Create does not need to be called manually. It is called when
ConfigurationSe ttings.GetConfi g(string) is called, dependent on what is
configured in the application's config file, in the configSections block.
I'm able to watch the code go through the Create routine everytime while
in the debugger, so that doesn't appear to be the problem.
Steve
Steve <ng*****@digita lnothing.com> wrote: I'm currently running into a problem, and I have no idea what to make of it.
Could you post a short but complete program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Steve <ng*****@digita lnothing.com> wrote in
news:eB******** ******@TK2MSFTN GP09.phx.gbl: Chris R. Timmons wrote: Steve,
Config.Create, which does the actual loading of the config data, is never called by either Config or ConnectionStrin gs.
Config.Create does not need to be called manually. It is called when ConfigurationSe ttings.GetConfi g(string) is called, dependent on what is configured in the application's config file, in the configSections block.
I'm able to watch the code go through the Create routine everytime while in the debugger, so that doesn't appear to be the problem.
Steve,
Sorry about that. I'm not as well informed about dynamic
configuration properties as I like to think I am :-).
I believe the custom section handler class Config needs to explicitly
declare it is implementing IConfigurationS ectionHandler in order for
its Create method to be called. Something like this:
public class Config : IConfigurationS ectionHandler
--
Hope this helps.
Chris.
-------------
C.R. Timmons Consulting, Inc. http://www.crtimmonsinc.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michelle |
last post by:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:
Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options.value)
My Code for the dropdown box is:
<form...
|
by: paul.driegen |
last post by:
Hi all,
Hopefully some gurus here can offer some insight into possible causes
of this problem..or at least point me in the right direction as to how
to solve it.
Consider:
|
by: Chris Capel |
last post by:
What is the rationale behind the decision not to allow abstract static class
members? It doesn't seem like it's a logically contradictory concept, or
that the implementation would be difficult or near-impossible. It seems like
it would be useful. In fact, there's a place in my code that I could make
good use of it. So why not?
Chris
|
by: Sergey Klementiev |
last post by:
Why it's impossible to have a static indexer in C#?
|
by: Sahil Malik [MVP] |
last post by:
So here's a rather simple question.
Say in an ASP.NET application, I wish to share common constants as static
variables in global.asax (I know there's web.config bla bla .. but lets just
say I wanna use global.asax) ---
Would you declare your static var as ---
public static int x ;
| |
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you experts.
I would like to produce Javascript classes that can be "subclassed"
with certain behaviors defined at subclass time. There are plenty of...
|
by: Dave Booker |
last post by:
It looks like the language is trying to prevent me from doing this sort of
thing. Nevertheless, the following compiles, and I'd like to know why it
doesn't work the way it should:
public class ComponentA
{
static string s_name = "I am the root class.";
public string Name { get {return s_name;} }
}
|
by: =?Utf-8?B?R29yZG8=?= |
last post by:
Hello everyone,
I've been trying for some time now to move to C++/CLI, but I have several
large legacy C++ static libraries I need to use. When I set up a simple
solution with a C++/CLI Winforms app and a C++ native static library, they
work well together _unless_ I have, it seems, any static variables defined in
any function in the native...
|
by: Tim Redfern |
last post by:
Hi I'm having an issue that is probably obvious to somebody here but its
baffling me..
I'm using python (2.5.1) on an embedded linux sytem system (kernel
2.6.19 I think) with only 32MB memory (for an art project).
My python code runs nicely when launched manually from a login shell, ps
shows its using 11MB or so of memory.
However,...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |