为什么会加入** **的appSettings节的App.config导致WPF应用程序错误?应用程序、错误、App、appSettings

由网友(爱你,无期徒刑)分享简介:在我的WPF应用程序(复合应用程序),我想存储变量在的App.config 文件,但只要我添加一个的appSettings 在应用部分。配置,它给了我这个错误:In my WPF application (Composite Application) I want to store a variable in the...

在我的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.

阅读全文

相关推荐

最新文章