【发布时间】:2016-12-11 01:12:14
【问题描述】:
我正在尝试将一些设置(例如我的连接)字符串保存在 .config 文件中。我在网上看到的大多数教程都是关于如何创建 .config 文件的状态,我应该手动添加一个现有的,但是我的程序已经自动创建了一个,并且我里面有以下代码:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc812dsac44d"/>
</DbProviderFactories>
</system.data></configuration>
现在,当我单击 app.config 文件的属性时,我不会收到任何错误消息。但是,当我在文本区域内单击时,会收到以下 3 条消息:
Could not find schema information for the attribute 'version'.
Could not find schema information for the attribute 'supportedRuntime'.
Could not find schema information for the attribute 'sku'.
所以我创建了另一个 app.config 文件并将其命名为“app2.config”。但是当我复制以下代码时
<appSettings>
<add key="path226" value="Application.StartupPath" />
</appSettings>
并尝试通过此代码检索值
MessageBox.Show(ConfigurationManager.AppSettings["path226"]);
我收到一个空白消息框。如果我在“app.config”中尝试相同的代码,它可以工作,但我收到 3 条错误消息。我不确定是否必须创建自己的 app.config 文件或使用现有文件。如果我必须使用现有的,我该如何解决我的错误?感谢您的帮助。
【问题讨论】: