exception when using app.config

T

Tony Johansson

Hi!

Here I have an example of a program that is using the app.config file that
is listed at the bottom.
The problem is that when I run this program I get an execption which is in
swedish but it say something like
"It occured an error when the sectionhandling for
MyFirstSectiongroup/MyFirstSection should be created. It not
possible to read the file or the composition ConnectionStringDemo or one of
its dependences."

Does anyone have any suggestion where to change ?
static void Main(string[] args)
{
try
{
Object o =
ConfigurationManager.GetSection("MyFirstSectionGroup/MyFirstSection");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}

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

//Tony
 
W

Willem van Rumpt

Tony said:
Hi!

Here I have an example of a program that is using the app.config file that
is listed at the bottom.
The problem is that when I run this program I get an execption which is in
swedish but it say something like
"It occured an error when the sectionhandling for
MyFirstSectiongroup/MyFirstSection should be created. It not
possible to read the file or the composition ConnectionStringDemo or one of
its dependences."

Does anyone have any suggestion where to change ?

The exception tells you that the configuration can't load the
configuration handler in the assembly and type you specified
(it can't find "ConnectionStringDemo.MyFirstSectionHandler" in assembly
"ConnectionStringDemo").

This could mean that the type or assembly does not exist, is not
referenced, or that you made a typo.

It could also indicate that you signed the assembly. In that case, you
need to specify the fullname for the type (i.e. including Version,
Culture, and PublicKeyToken), something like:

<section name="MyFirstSection"
type="Assembly.TypeName, Assembly, Version=1.2.3.4,
Culture=xxxx,PublicKeyToken=xxxx "/>
 
T

Tony Johansson

Willem van Rumpt said:
The exception tells you that the configuration can't load the
configuration handler in the assembly and type you specified
(it can't find "ConnectionStringDemo.MyFirstSectionHandler" in assembly
"ConnectionStringDemo").

This could mean that the type or assembly does not exist, is not
referenced, or that you made a typo.

It could also indicate that you signed the assembly. In that case, you
need to specify the fullname for the type (i.e. including Version,
Culture, and PublicKeyToken), something like:

<section name="MyFirstSection"
type="Assembly.TypeName, Assembly, Version=1.2.3.4,
Culture=xxxx,PublicKeyToken=xxxx "/>

It works now thanks to you!!

//Tony
 
Top