如何修复错误:"无法通过创建架构找到属性/元素的架构信息"

Bri*_*thy 147 c# error-handling application-settings database-schema

我有一个使用C#在VS2010中编写的Windows窗体应用程序,并在app.config文件中获得以下错误:

Message 4   Could not find schema information for the attribute 'name'
Message 8   Could not find schema information for the attribute 'name'
Message 12  Could not find schema information for the attribute 'name'
Message 5   Could not find schema information for the attribute 'serializeAs'
Message 15  Could not find schema information for the element 'CCP_Utility.Settings1'
Message 2   Could not find schema information for the element 'CCP_Utility.Properties.Settings'
Message 3   Could not find schema information for the element 'setting'
Message 1   Could not find schema information for the element 'userSettings'
Message 6   Could not find schema information for the element 'value'
Run Code Online (Sandbox Code Playgroud)

我需要更改代码才能解决此问题?我在哪里可以编辑内容CCP_Utility.Settings1CCP_Utility.Properties.Settings

这是app.config代码:

<configuration>
<configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
        <section name="CCP_Utility.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        <section name="CCP_Utility.Settings1" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
  </configSections>
<userSettings>
  <CCP_Utility.Properties.Settings>
    <setting name="SourceDir" serializeAs="String">
      <value />
    </setting>
    <setting name="TargetDir" serializeAs="String">
      <value />
    </setting>
    <setting name="CorpID" serializeAs="String">
      <value />
    </setting>
  </CCP_Utility.Properties.Settings>
    <CCP_Utility.Settings1>
        <setting name="sourceDir" serializeAs="String">
            <value />
        </setting>
        <setting name="targetDir" serializeAs="String">
            <value />
        </setting>
    </CCP_Utility.Settings1>

   </userSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

ree*_*key 210

解决问题的最快,最简单的方法:

  1. 在解决方案资源管理器中右键单击项目图标,然后选择"属性".
  2. 转到"应用程序"选项卡,然后选择早期的.NET目标框架.
  3. 保存更改.
  4. 转到"应用程序"选项卡,然后选择最初的.NET目标框架.
  5. 保存更改=>问题解决了!

  • 在Visual Studio 2015中为我工作.如果有人可以解释原因,那将会很好. (23认同)
  • 甜!在VS2012为我工作. (10认同)
  • 也为我工作(VS2013 Premium). (4认同)
  • 这可能在第一次尝试时不起作用.在VS 2013 Express中工作之前我需要做两次. (4认同)
  • 没用,VS2015更新2,.NET 4.5.2.看起来它会让消息消失,但如果你再次打开XML文件,它们就会回来. (4认同)

rsb*_*rro 168

更新2015年9月
这个答案继续得到提升,所以我会把它留在这里,因为它似乎对某些人有帮助,但请先查看@reexmonkey@Pressacco的其他答案.它们可能会提供更好的结果

原始答案
给出一个镜头:

  1. 在Visual Studio中,打开app.config或web.config文件.
  2. 转到"XML"菜单并选择"Create Schema".此操作应创建一个名为"app.xsd"或"web.xsd"的新文件.
  3. 将该文件保存到磁盘.
  4. 返回app.config或web.config,在编辑窗口中右键单击并选择属性.从那里,确保在Schemas属性中引用刚刚生成的xsd.如果它不存在则添加它.

这应该会导致这些消息消失.

我将web.xsd保存在我的web文件夹的根目录中(可能不是最适合它的地方,但仅用于演示目的),我的Schemas属性如下所示:

"C:\ Program Files(x86)\ Microsoft Visual Studio 10.0\xml\Schemas\DotNetConfig.xsd""Web.xsd"

  • @rsbarro,谢谢你的回复!为什么你有2个xsd文件?我创建了模式,并提出了一个文件-app.xsd,我保存到根目录.错误消失了,但现在我得到一个警告:"全局元素'配置'已被宣布".有关如何解决此问题的任何想法? (10认同)
  • 不不不!!这不是"解决方案",因为它甚至不是一个真正的问题.查看并投票给@ pressacco的回答.reexmonkey的答案也有效.为什么这个答案得到如此多的积极投票?1.完全忽略!关闭app.config或web.config并编译您甚至不会看到消息.2.虽然没有必要,通过右键单击.config属性来解决,以纠正VS提供的XSD的路径.(@ pressacco的答案)3.或者:更改项目设置DotNet版本并返回.重复两次.(reexmonkey的答案).可能会导致包更新出现问题. (9认同)
  • 生成Web.xsd文件时,只包括您在web/app.config部分(用户部分)中添加的模式.排除已包含在默认架构或其他.xsd中的所有其他内容. (6认同)
  • 谢谢.这很有用,但是有一个很好的地方我可以阅读以了解为什么会发生这种情况?在为DotNetOpenAuth添加大量内容然后从头开始重新生成edmx文件之后,似乎我突然需要为web.config生成模式.这在"你改变了很多东西,所以有些东西被扯下来"中是有道理的.有点方法,但知道为什么web.config文件会自发地需要一个模式会很有帮助. (3认同)
  • 只需使用"属性"对话框选择架构或添加其他架构即可.查看app.config时,右键单击编辑器窗口并选择"属性".您应该在弹出的Property Editor控件中看到Schemas.此外,如果单击Schemas中的"..."按钮,则可以使用漂亮的GUI选择要用于配置文件的模式. (2认同)

Pre*_*cco 21

EntLib 5包含一个XSD,它安装在Visual Studio架构目录中.就我而言,它可以在以下位置找到:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\EnterpriseLibrary.Configuration.xsd
Run Code Online (Sandbox Code Playgroud)

CONTEXT

  • Visual Studio 2010
  • 企业图书馆5

消除警告的步骤

  1. 在Visual Studio项目中打开app.config
  2. 右键单击XML Document编辑器,选择"Properties"
  3. 将完全限定的路径添加到"EnterpriseLibrary.Configuration.xsd"

在旁边

值得重复的是,这些"错误列表""消息"("无法找到元素的架构信息")仅在打开app.config文件时可见.如果您"关闭所有文档"并编译...将不会报告任何消息.

  • Visual Studio 2015中是否缺少EnterpriseLibrary.Configuration.xsd? (8认同)
  • 简单地关闭XML文件就会让问题消失 (3认同)