B
Brad Wood
Here is perhaps the simplest possible ConfigurationSection sample along
with it's App.Config:
======================================================
using System;
using System.Configuration;
namespace ConsoleApplication1
{
class Program
{
public class BoboSection : ConfigurationSection
{
[ConfigurationProperty("mom", IsRequired = true)]
public string mom
{
get { return (string)base["mom"]; }
set { base["mom"] = value; }
}
}
static void Main( string[] args )
{
BoboSection bobo =
(BoboSection)ConfigurationManager.GetSection("Bobo");
Console.WriteLine( bobo.mom );
Console.ReadLine();
}
}
}
======================================================
<configuration>
<configSections>
<section name="Bobo" type="BoboSection, ConsoleApplication1" />
</configSections>
<Bobo mom="hi mom" />
</configuration>
======================================================
When I run this, I get the error, "An error occurred creating the
configuration section handler for Bobo: Could not load type
'BoboSection' from assembly 'ConsoleApplication1'".
The path to ConsoleApplication1.exe is shown correctly. It makes no
difference if I change the section element's type attribute to
"ConsoleApplication1.BoboSection, ConsoleApplication1" or if I give the
full name of the assembly (ConsoleApplication1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null).
with it's App.Config:
======================================================
using System;
using System.Configuration;
namespace ConsoleApplication1
{
class Program
{
public class BoboSection : ConfigurationSection
{
[ConfigurationProperty("mom", IsRequired = true)]
public string mom
{
get { return (string)base["mom"]; }
set { base["mom"] = value; }
}
}
static void Main( string[] args )
{
BoboSection bobo =
(BoboSection)ConfigurationManager.GetSection("Bobo");
Console.WriteLine( bobo.mom );
Console.ReadLine();
}
}
}
======================================================
<configuration>
<configSections>
<section name="Bobo" type="BoboSection, ConsoleApplication1" />
</configSections>
<Bobo mom="hi mom" />
</configuration>
======================================================
When I run this, I get the error, "An error occurred creating the
configuration section handler for Bobo: Could not load type
'BoboSection' from assembly 'ConsoleApplication1'".
The path to ConsoleApplication1.exe is shown correctly. It makes no
difference if I change the section element's type attribute to
"ConsoleApplication1.BoboSection, ConsoleApplication1" or if I give the
full name of the assembly (ConsoleApplication1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null).