gpt4 book ai didi

c# - 如何在 C# 中配置 App.config 文件

转载 作者:行者123 更新时间:2023-11-30 19:30:09 25 4
gpt4 key购买 nike

我使用的是 Visual Studio 2005,我用“App.config”文件创建了一个应用程序。当我尝试编辑并向该 App.config 文件添加新值时它显示错误请帮助我..

我的 app.config 文件包含:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="keyvalue" value="value"/>
<add key="keyvalue1" value="value1"/>
</appSettings>
<mySettings>
<add name="myname" myvalue="value1"/>
</mySettings>
</configuration>

错误显示为:

Could not find schema information for the element "mySettings"
Could not find schema information for the element "add"
Could not find schema information for the element "myvalue"

最佳答案

不要创建“MySettings”组。将您需要的任何内容放入 AppSettings 组。

您可以创建一个 mySettings 组,但如果您包含自定义(非标准)配置部分,则必须按照描述在 configSections 元素中声明它们 herehere .

我会质疑这是否真的有必要,但是除非有充分的理由添加自定义部分,否则我会继续我的第一个答案,因为最好遵循正常标准。它只是让 future 的维护程序员更容易。

关于c# - 如何在 C# 中配置 App.config 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9909163/

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