PC Review


Reply
Thread Tools Rate Thread

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

 
 
mcstrini@fastmail.fm
Guest
Posts: n/a
 
      12th Nov 2007
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(ReportServerUrlElement),
CollectionType =
ConfigurationElementCollectionType.AddRemoveClearMap)]
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)?

 
Reply With Quote
 
 
 
 
mcstrini@fastmail.fm
Guest
Posts: n/a
 
      12th Nov 2007
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).


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Configuration Sections in Location Tag David Williams Microsoft ASP .NET 4 3rd Oct 2008 05:04 PM
Custom Configuration Sections... Jason Richmeier Microsoft Dot NET 1 12th Sep 2008 04:54 PM
Custom Configuration file Sections in 2.0 =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= Microsoft VB .NET 3 1st Mar 2006 02:13 PM
Custom Configuration Sections in 2.0 uttara Microsoft VB .NET 0 9th Jan 2006 11:47 PM
Custom Configuration Sections =?Utf-8?B?RWxpeWFodSBCYWtlcg==?= Microsoft Dot NET Framework 0 17th Jun 2004 11:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:54 AM.