Cant read custom section in app.config file.

G

Guest

Take a look at my custom configSections definition below. I cant seem to use

ConfigurationSettings.GetConfig("referencedAssemblies"
o
ConfigurationSettings.GetConfig("assembly"

to work in order to read the values defined. Can someone help me with this? Below the config section is the code i've tried using to read the config file

<configuration><configSections><sectionGroup name="referencedAssemblies"><section name="assembly" type="System.Configuration.SingleTagSectionHandler" allowLocation="false"/></sectionGroup></configSections><referencedAssemblies><assembly path="c:\one.dll" /><assembly path="c:\two.dll" /><assembly path="c:\three.dll" /></referencedAssemblies></configuration

IDictionary languages = (IDictionary)ConfigurationSettings.GetConfig("referencedAssemblies")
IDictionary languages = (IDictionary)ConfigurationSettings.GetConfig("languages")

Both are null
 
J

Joel Hendrix [MSFT]

I don't know the requirements of your design, but based on your post one
idea I came up with is this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="referencedAssemblies">
<section name="assembly"
type="System.Configuration.NameValueSectionHandler" allowLocation="false"/>
</sectionGroup>
</configSections>
<referencedAssemblies>
<assembly>
<add key="one" value="c:\one.dll" />
<add key="two" value="c:\two.dll" />
<add key="three" value="c:\three.dll" />
</assembly>
</referencedAssemblies>
</configuration>

NameValueCollection test1 =
(NameValueCollection)ConfigurationSettings.GetConfig("referencedAssemblies/a
ssembly");

This will read all of the assemblies referenced in the <assembly> section
into a NameValueCollection class.
--------------------
Thread-Topic: Cant read custom section in app.config file.
thread-index: AcQFZLqqf5/grpduT7yeBizHXwmQ/g==
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
From: "=?Utf-8?B?am9obg==?=" <[email protected]>
Subject: Cant read custom section in app.config file.
Date: Mon, 8 Mar 2004 15:26:05 -0800
Lines: 16
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.languages.csharp
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:227433
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

Take a look at my custom configSections definition below. I cant seem to
use

ConfigurationSettings.GetConfig("referencedAssemblies")
or
ConfigurationSettings.GetConfig("assembly")

to work in order to read the values defined. Can someone help me with
this? Below the config section is the code i've tried using to read the
config file.

<configuration><configSections><sectionGroup
name="referencedAssemblies"><section name="assembly"
type="System.Configuration.SingleTagSectionHandler"
allowLocation="false"/> said:
<assembly path="c:\one.dll" /><assembly path="c:\two.dll" /><assembly
path="c:\three.dll" /></referencedAssemblies></configuration>


IDictionary languages =
(IDictionary)ConfigurationSettings.GetConfig("referencedAssemblies");
IDictionary languages =
(IDictionary)ConfigurationSettings.GetConfig("languages");

Both are null.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top