views:

514

answers:

2

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?

+6  A: 

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.

Andrew Hare
A: 

But how can I declare both configSections and system.ServiceModel tags in one app.config? I definitely need to use them both

vladix