为什么在App.config中添加**appSettings**部分会导致WPF应用程序出错?

Edw*_*uay 5 .net wpf app-config prism

在我的WPF应用程序(复合应用程序)中,我想在App.config文件中存储一个变量,但是只要在App.config中添加appSettings部分,它就会给我这个错误:

System.Windows.Application的类型初始值设定项引发了异常.

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...
Run Code Online (Sandbox Code Playgroud)

总的来说,我知道这是有效的,因为我可以在这样的简单应用程序中使用它.

什么可能导致上述错误,我将如何解决它,以便我可以简单地将变量添加到App.config文件?

And*_*are 25

似乎抱怨您已将<appSettings>节点放在节点上方<configSections>.将<configSections>节点移动到顶部是文件中的第一个元素或将其删除(因为您似乎没有使用它).

来自configSections元素:

如果configSections元素位于配置文件中,则configSections元素必须是配置元素的第一个子元素.