473,480 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Baffling static property issue.

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(authenticat edUser,
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;}
}
}
}
Nov 16 '05 #1
4 1506
Steve,

Config.Create, which does the actual loading of the config data, is
never called by either Config or ConnectionStrings.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
Chris R. Timmons wrote:
Steve,

Config.Create, which does the actual loading of the config data, is
never called by either Config or ConnectionStrings.


Config.Create does not need to be called manually. It is called when
ConfigurationSettings.GetConfig(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
Nov 16 '05 #3
Steve <ng*****@digitalnothing.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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Steve <ng*****@digitalnothing.com> wrote in
news:eB**************@TK2MSFTNGP09.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 ConnectionStrings.


Config.Create does not need to be called manually. It is called
when ConfigurationSettings.GetConfig(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 IConfigurationSectionHandler in order for
its Create method to be called. Something like this:

public class Config : IConfigurationSectionHandler
--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1954
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...
2
1421
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:
33
3313
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...
12
24723
by: Sergey Klementiev | last post by:
Why it's impossible to have a static indexer in C#?
25
5115
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...
11
3791
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...
14
33217
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...
6
10319
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...
1
1279
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...
0
7037
marktang
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,...
0
7034
Oralloy
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,...
0
6886
tracyyun
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...
0
5324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2990
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...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
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 ...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.