473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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("ReportServerUrls")
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" ?>
<configuration>
<configSections>
[...]
<section name="ReportServerUrls"
type="[...]DbConfiguration.ReportServerUrlSection,
[...]DbConfiguration"/>
[...]
</configSections>
[...]
<ReportServerUrls>
<urls>
<add dbInstance="TEST" url=[...] />
</urls>
</ReportServerUrls>
</configuration>

the classes for the custom section, with appropriate attributes:
public class ReportServerUrlElement : ConfigurationElement
{
private static ConfigurationProperty propDbInstance;
private static ConfigurationProperty propUrl;

[ConfigurationProperty("dbInstance", IsRequired = true)]
public string DbInstance
{
get { return (string)base[propDbInstance]; }
}

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

protected override ConfigurationPropertyCollection Properties
{
get
{
return base.Properties;
}
}

static ReportServerUrlElement()
{
propDbInstance =
new ConfigurationProperty(
"dbInstance", typeof(string), null,
ConfigurationPropertyOptions.IsRequired
);
propUrl =
new ConfigurationProperty(
"url", typeof(string), null,
ConfigurationPropertyOptions.IsRequired
);
}
}

[ConfigurationCollection(typeof(ReportServerUrlElem ent),
CollectionType =
ConfigurationElementCollectionType.AddRemoveClearM ap)]
public class ReportServerUrlCollection :
ConfigurationElementCollection
{
public override ConfigurationElementCollectionType
CollectionType
{
get { return base.CollectionType; }
}
public ReportServerUrlElement this[int index]
{
get { return
(ReportServerUrlElement)base.BaseGet(index); }
}
public ReportServerUrlElement this[string dbInstance]
{
get { return
(ReportServerUrlElement)base.BaseGet(dbInstance); }
}

private static ConfigurationPropertyCollection properties;

protected override ConfigurationPropertyCollection Properties
{
get { return properties; }
}

static ReportServerUrlCollection()
{
properties = new ConfigurationPropertyCollection();
}

protected override ConfigurationElement CreateNewElement()
{
return new ReportServerUrlElement();
}

protected override object GetElementKey(ConfigurationElement
element)
{
return (element as ReportServerUrlElement).DbInstance;
}
}

public class ReportServerUrlSection : ConfigurationSection
{
private static ConfigurationProperty propUrls;
private static ConfigurationPropertyCollection properties;

[ConfigurationProperty("urls")]
public ReportServerUrlCollection Urls
{
get { return (ReportServerUrlCollection)
(base[propUrls]); }
}

public ReportServerUrlSection() : base()
{
propUrls =
new ConfigurationProperty(
"urls",
typeof(ReportServerUrlCollection),
new ReportServerUrlCollection(),
ConfigurationPropertyOptions.None
);

properties = new ConfigurationPropertyCollection();
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
OpenExeConfiguration(path)). But config.GetSection("ReportServerUrls")
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 5908
On Nov 12, 5:33 am, mcstr...@fastmail.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
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...
5
by: rdcpro | last post by:
In reading MSDN docs on creating custom Configuration sections, I found this page: ...
1
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...
0
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...
0
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...
0
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...
4
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,...
1
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...
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.