473,800 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom configuration sections --- why might GetSection return null?

I'm trying to have my application use a special config file which is
shared across servers, and want to include a custom section (for URLs
of report services associated with database instances). However, my
section doesn't seem to be recognized (GetSection("Re portServerUrls" )
returns null). I don't really see how what I'm doing differs from the
usage examples I've found.

I have my XML config itself:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
[...]
<section name="ReportSer verUrls"
type="[...]DbConfiguration .ReportServerUr lSection,
[...]DbConfiguration "/>
[...]
</configSections>
[...]
<ReportServerUr ls>
<urls>
<add dbInstance="TES T" url=[...] />
</urls>
</ReportServerUrl s>
</configuration>

the classes for the custom section, with appropriate attributes:
public class ReportServerUrl Element : ConfigurationEl ement
{
private static ConfigurationPr operty propDbInstance;
private static ConfigurationPr operty propUrl;

[ConfigurationPr operty("dbInsta nce", IsRequired = true)]
public string DbInstance
{
get { return (string)base[propDbInstance]; }
}

[ConfigurationPr operty("url", IsRequired = true)]
public string Url
{
get { return (string)base[propUrl]; }
}

protected override ConfigurationPr opertyCollectio n Properties
{
get
{
return base.Properties ;
}
}

static ReportServerUrl Element()
{
propDbInstance =
new ConfigurationPr operty(
"dbInstance ", typeof(string), null,
ConfigurationPr opertyOptions.I sRequired
);
propUrl =
new ConfigurationPr operty(
"url", typeof(string), null,
ConfigurationPr opertyOptions.I sRequired
);
}
}

[ConfigurationCo llection(typeof (ReportServerUr lElement),
CollectionType =
ConfigurationEl ementCollection Type.AddRemoveC learMap)]
public class ReportServerUrl Collection :
ConfigurationEl ementCollection
{
public override ConfigurationEl ementCollection Type
CollectionType
{
get { return base.Collection Type; }
}
public ReportServerUrl Element this[int index]
{
get { return
(ReportServerUr lElement)base.B aseGet(index); }
}
public ReportServerUrl Element this[string dbInstance]
{
get { return
(ReportServerUr lElement)base.B aseGet(dbInstan ce); }
}

private static ConfigurationPr opertyCollectio n properties;

protected override ConfigurationPr opertyCollectio n Properties
{
get { return properties; }
}

static ReportServerUrl Collection()
{
properties = new ConfigurationPr opertyCollectio n();
}

protected override ConfigurationEl ement CreateNewElemen t()
{
return new ReportServerUrl Element();
}

protected override object GetElementKey(C onfigurationEle ment
element)
{
return (element as ReportServerUrl Element).DbInst ance;
}
}

public class ReportServerUrl Section : ConfigurationSe ction
{
private static ConfigurationPr operty propUrls;
private static ConfigurationPr opertyCollectio n properties;

[ConfigurationPr operty("urls")]
public ReportServerUrl Collection Urls
{
get { return (ReportServerUr lCollection)
(base[propUrls]); }
}

public ReportServerUrl Section() : base()
{
propUrls =
new ConfigurationPr operty(
"urls",
typeof(ReportSe rverUrlCollecti on),
new ReportServerUrl Collection(),
ConfigurationPr opertyOptions.N one
);

properties = new ConfigurationPr opertyCollectio n();
properties.Add( propUrls);
}
}

and then, as far as I can tell, this is going into a DLL with the same
name included in the "type" attribute of the "section" element in the
config XML, in the same directory with the executables and the config
file itself. (I'm opening the config file with
OpenExeConfigur ation(path)). But config.GetSecti on("ReportServe rUrls")
still returns null. Any ideas on what could be the problem (or even
what I could do to get more info. on the problem)?

Nov 12 '07 #1
1 5933
On Nov 12, 5:33 am, mcstr...@fastma il.fm wrote:
I'm trying to have my application use a special config file which is
shared across servers
Sorry, I meant "shared across multiple executables" (specifically, a
client app and a server-configuration app).
Nov 12 '07 #2

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

Similar topics

3
1926
by: Robert | last post by:
I have an application with custom configuration sections in it's app.config file. Here's a shortened excerpt: <monitors> <monitor type="SystemMonitor.Monitors.NetworkAvailabilityMonitor,SystemMonitor"> <notifiers> <notifier type="SystemMonitor.Notifiers.MessageBoxNotifier,SystemMonitor" />
5
2282
by: rdcpro | last post by:
In reading MSDN docs on creating custom Configuration sections, I found this page: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfcustomelementfornamevaluesectionhandlerdictionarysectionhandler.asp At the very bottom, it says: Configuration File This element can be used in the application configuration file, machine configuration file (Machine.config), and Web.config files that are not at the
1
1611
by: Paloma García | last post by:
Dear all, I have created personalized configuration sections in my web project following the instructions described in this page http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconDeclaringCustomConfigurationSections.asp The problem is that I using the same code and I get the error "Object reference not set to an instance of an object" in the line where I try to read the first parameter (in the page...
0
920
by: uttara | last post by:
I was going through the following article on msdn 2.0 on how to use the custom configuration section. http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx The custom config section it shows is this: <myCustomGroup> <myCustomSection myAttrib1="Clowns"> <myChildSection myChildAttrib1="Zippy" myChildAttrib2="Michael Zawondy "/> </myCustomSection>
0
1093
by: Michael | last post by:
Hi, I would like to know if it is possible to use the ConfigurationSection class to modify user settings. I have created custom configuration classes that derive from ConfigurationSetion and which I access using the ConfigurationManager.GetSection method. This all works fine, but it only outputs to the app.config file. Is it possible to output the settings the user.config file?
0
1625
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root level web.config and an application level web.config, with the application web.config inheriting from the root level web.config. I am receiving the following message when compiling the web application... "....Section or group name...
4
2699
balabaster
by: balabaster | last post by:
Okay, I decided that I needed to understand the whole custom configuration file bits and so I've spent some time playing around with it. It seems (in the most) relatively straight forward. However, I've come unstuck with one scenario that I'm trying to figure out the code for: Consider the following configuration: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="DummySection"...
1
1634
by: =?Utf-8?B?SmFzb24gUmljaG1laWVy?= | last post by:
This may have been addressed in another post but I was unable to find what I was looking for. I am trying to create a custom configuration section that is element-centric instead of attribute-centric (mostly out of preference). For example... <Date> <Year>2008</Year>
4
1669
by: David Williams | last post by:
I am familiar with creating custom configuration settings and accessing them. However, for a current requirement, I need to control the various settings in my custom configuration section by virtual location of the pages accessing the configuration information. The best way that I know is to do this via the use of the location tag in the web.config. However, I can not seem to get the correct instance of the configuration section in my...
0
9691
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, 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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10505
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, 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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
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 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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4149
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.