What is the criteria for the type attribute for the section element in application config file.


T

Tony Johansson

Hi!

In Main below I use the GetSection to fetch a specific section from the app
config file. When I specify which sectionhandler to use I use the type
attribute on the section element in this way see (*) below. This section is
part of the whole app config file which is listed at the bottom.
(*)
<sectionGroup name="MyFirstSectionGroup">
<section name="MyFirstSection" type="ConfigTest.MyFirstSectionHandler,
ClassLibrary1" />
</sectionGroup>

Now to my question ClassLibrary1 in the type argument above is a class
library where the method Create is located which is my actual
sectionhandler.
I just wonder assume if Main is located in assembly name ConsoleApp then I
have hopped to be able to use this assembly
in the type argument above like this.
<sectionGroup name="MyFirstSectionGroup">
<section name="MyFirstSection" type="ConfigTest.MyFirstSectionHandler,
ConsoleApp " />
</sectionGroup>
but .NET doesn't like that.
So as a summary if you run main from assembly X it seems to me that it's
impossible to also have
assembly x in the type argument for the section.

static void Main(string[] args)
{
Object o =
ConfigurationManager.GetSection("MyFirstSectionGroup/MyFirstSection");
}

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="MyFirstSectionGroup">
<section name="MyFirstSection" type="ConfigTest.MyFirstSectionHandler,
ClassLibrary1" />
</sectionGroup>
</configSections>
<MyFirstSectionGroup>
<MyFirstSection>
<Value>
<Identifier>111</Identifier>
<SettingValue>System.DataSqlClient</SettingValue>
</Value>
<Value>
<Identifier>112</Identifier>
<SettingValue>System.Data.OleDb</SettingValue>
</Value>
</MyFirstSection>
</MyFirstSectionGroup>
</configuration>

//Tony
 
Ad

Advertisements


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