gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 00:25:02 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com