Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would adding an **appSettings** section to App.config cause an error in WPF application?

In my WPF application (Composite Application) I want to store a variable in the App.config file, but as soon as I add an appSettings section in App.config, it gives me this error:

The type initializer for System.Windows.Application threw an exception.

App.Config:

<?xml version="1.0" encoding="utf-8" ?>
  <configuration>
      <appSettings>
          <add key="SmartFormMockDirectory" value="C:\test"/>
      </appSettings>
    <configSections>
    </configSections>
    <system.serviceModel>
      <bindings>
        <basicHttpBinding>
          <binding name="Service1Soap" closeTimeout="00:01:00" openTimeout="00:01:00"
            receiveTime...

In general I know this works since I can get it to work in simple applications like this.

What could be causing the above error and how would I fix it so I can simply add variables to the App.config file?

like image 384
Edward Tanguay Avatar asked Aug 03 '09 15:08

Edward Tanguay


1 Answers

It seems to be complaining that you have placed your <appSettings> node above the <configSections> node. Either move the <configSections> node to the top to be the first element in the file or remove it (as you don't seem to be using it).

From configSections Element:

If the configSections element is in a configuration file, the configSections element must be the first child element of the configuration element.

like image 182
Andrew Hare Avatar answered Oct 20 '22 19:10

Andrew Hare