1

I have a .NET 4.7 application. In this application, I have several custom configuration elements that I want to use in the App.config file. For that reason, I've defined several configuration related classes in my project. This project compiles and it's structured like this:

./
  /ConfigurationItems
    Children
    Child
  App.config
  Program.cs

In my App.config file, I have the following:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="Children" type="MyOrg.MyApp.ConfigurationItems.Children, MyOrg.MyApp.exe" />
  </configSections>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
  </startup>  

  <Children>
    <Child Name="Joe" />
    <Child Name="Suzy" />
  </Children>  
</configuration>

When I run this application, I get to the following line:

  var children = ConfigurationManager.GetSection("Children") as MyOrg.MyApp.ConfigurationItems.Children;

At that point, I receive the following exception:

System.Configuration.ConfigurationErrorsException: 'An error occurred creating the configuration section handler for Children: Could not load file or assembly 'MyOrg.MyApp.exe' or one of its dependencies. The system cannot find the file specified.'

FileNotFoundException: Could not load file or assembly 'MyOrg.MyApp.exe' or one of its dependencies. The system cannot find the file specified.

What am I doing wrong? How do I use custom configuration elements defined in the project that I want to use them in?

Thank you

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Some User
  • 5,257
  • 13
  • 51
  • 93

1 Answers1

0

Remove the ".exe" file extension in the type attribute from the <section> element:

  <configSections>
    <section name="Children" type="MyOrg.MyApp.ConfigurationItems.Children, MyOrg.MyApp" />
  </configSections>
sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40