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

标签 .net wpf prism app-config

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

The type initializer for System.Windows.Application threw an exception.



应用配置:
<?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...

总的来说,我知道这有效 since I can get it to work in simple applications like this .

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

最佳答案

似乎在提示您已经放置了您的 <appSettings> <configSections>上方的节点节点。要么移动<configSections>节点到顶部成为文件中的第一个元素或将其删除(因为您似乎没有使用它)。

来自 configSections Element :

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

关于.net - 为什么在 App.config 中添加 **appSettings** 部分会导致 WPF 应用程序出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1223142/

相关文章:

.net - 在 M-V-VM 中,我的代码在哪里?

wpf - 仅在设计时使用 MultiBindingConverter 获取 XamlObjectWriterException (Visual Studio 2015)

unity-container - EventAggregator - 获取订阅者列表

c# - ASP.NET MVC 如何知道如何填充您的模型以提供 Controller 的操作?它涉及反射(reflection)吗?

c# - Windows Forms .NET 中的 DataGridViewRow 线程安全

c# - C#/.NET 编译器不警告 Dispose() 有什么原因吗?

.net - 使用网络摄像头在WP7仿真器中模拟手机摄像头

c# - 识别事件键是否为文本(不仅是字母数字)

mvvm - RegisterType <>在Silverlight上不可见

c# - 在 Prism 6 中加载所有模块后使用 ViewModel 初始化 Shell