Home > development, windows > App.Config: Order matters

App.Config: Order matters

2011/09/23

Note to self:

Within an App/Web.config in .NET… The startup node must be the last node…

Example: Create a plain WPF application from Visual Studio 2010, add an App.Config file, and try building Option 1 and Option 2 below.

Option 1:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
  <configSections />
</configuration>

This throws: “The type initializer for ‘System.Windows.Application’ threw an exception.”

Option 2:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections />
  <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
</configuration>

Fine.

Do I want to read 2.5MB of

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\DotNetConfig.xsd

? No.

Advertisements
  1. Vincent
    2011/11/09 at 22:36

    I have had this exact same issue. The node in my App.config file cause my node not to load properly. Although when I experienced this I was also writing a custom configurationSections class. So naturally, I thought I was just writing this section incorrectly. After banging my head for a couple of hours I played around and finally remove the node. Then BOOM. It worked. Do you have any idea why?

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: