为什么会加入** **的appSettings节的App.config导致WPF应用程序错误? [英] Why would adding an **appSettings** section to App.config cause an error in WPF application?

查看:381
本文介绍了为什么会加入** **的appSettings节的App.config导致WPF应用程序错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

的类型初始   System.Windows.Application抛出   例外。

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...

总的来说,我知道这工作因为我可以得到它的工作简单的应用程序是这样

什么引起上面的错误,我将如何解决它,所以我可以简单的变量添加到app.config文件?

推荐答案

这似乎是抱怨,你已经把你的&LT;的appSettings&GT; 节点上面的&LT; configSections&GT; 节点。无论是移动&LT; configSections&GT; 节点,顶端是文件中的第一个元素或将其删除(因为你似乎没有使用它)

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).

configSections 元素

如果所述configSections元件处于   配置文件,所述configSections   元素必须是第一个孩子   配置元素的元素

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

这篇关于为什么会加入** **的appSettings节的App.config导致WPF应用程序错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆