【问题标题】:error: This operation would create an incorrectly structured document错误:此操作将创建结构不正确的文档
【发布时间】:2013-11-13 21:21:54
【问题描述】:

我一直在尝试安装实体框架6,它总是回滚并出现错误

error: This operation would create an incorrectly structured document.

我已经卸载了对该位置提到的每个 dll 的所有引用。 http://entityframework.codeplex.com/wikipage?title=Updating%20Applications%20to%20use%20EF6

疯狂的是,我可以创建一个新项目,创建一个 webAPI 程序,并尝试添加 Entity Framework 6,但我得到了同样的错误,即使在删除了对 System.Data.Entity.dll 的所有引用之后也是如此 我已经了解了几天,需要认真的帮助。

如何安装 Entity Framework 6?

注意:它只会安装 find 到类库,而不是 WebApi 或 MVC 应用程序。


如果有帮助,这里有一些更详细的错误信息。

PM> Install-Package EntityFramework -Version 6.0.0
Installing 'EntityFramework 6.0.0'.
Successfully installed 'EntityFramework 6.0.0'.
Adding 'EntityFramework 6.0.0' to AC.
Successfully added 'EntityFramework 6.0.0' to AC.
System.InvalidOperationException: This operation would create an incorrectly structured document.
   at System.Xml.Linq.XDocument.ValidateDocument(XNode previous, XmlNodeType allowBefore, XmlNodeType allowAfter)
   at System.Xml.Linq.XDocument.ValidateNode(XNode node, XNode previous)
   at System.Xml.Linq.XContainer.AddNodeSkipNotify(XNode n)
   at System.Xml.Linq.XContainer.AddContentSkipNotify(Object content)
   at System.Xml.Linq.XContainer.Add(Object content)
   at System.Data.Entity.Migrations.Extensions.XContainerExtensions.GetOrCreateElement(XContainer container, String elementName, XAttribute[] attributes)
   at System.Data.Entity.ConnectionFactoryConfig.ConfigFileManipulator.AddOrUpdateConfigSection(XDocument config, Version entityFrameworkVersion)
   at System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand.<>c__DisplayClass3.<Execute>b__1(XDocument c)
   at System.Data.Entity.ConnectionFactoryConfig.ConfigFileProcessor.ProcessConfigFile(ProjectItem configItem, IEnumerable`1 manipulators)
   at System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand.<>c__DisplayClass3.<Execute>b__0(ProjectItem i)
   at System.Data.Entity.ConnectionFactoryConfig.ConfigFileFinder.FindConfigFiles(ProjectItems items, Action`1 action)
   at System.Data.Entity.ConnectionFactoryConfig.InitializeEntityFrameworkCommand.Execute()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Uninstalling 'EntityFramework 6.0.0'.
Successfully uninstalled 'EntityFramework 6.0.0'.
Install failed. Rolling back...
Install-Package : This operation would create an incorrectly structured document.
At line:1 char:16
+ Install-Package <<<<  EntityFramework -Version 6.0.0
    + CategoryInfo          : NotSpecified: (:) [Install-Package], RuntimeException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

【问题讨论】:

  • 我也遇到了同样的问题,你找到解决办法了吗?
  • 这里也一样..仍然没有解决方案:-(?

标签: c# asp.net-web-api entity-framework-6


【解决方案1】:

我遇到了同样的问题。事实证明,我正在将 EF 添加到我的一个非常老的项目中,并且 web.config 为 &lt;configuration /&gt; 元素定义了这个命名空间:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

删除该命名空间声明 (xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0") 有助于解决此问题。

【讨论】:

  • 谢谢!我有同样的旧项目,删除命名空间也对我有帮助。
  • 从 web.config 中删除 xmlns 也为我解决了这个问题,我已经尝试安装 Entity Framework 2 天,这为我解决了这个问题 :)
【解决方案2】:

我遇到了同样的问题,发现原因是 web.config 文件中的元素。就我而言,我改变了这个:

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

到这里:

<configuration>

这样就解决了。

【讨论】:

    【解决方案3】:

    升级 Entity Framework 时,app.config 或 web.config 文件将写入内容。我怀疑这可能是问题所在。查看您的 app.config 或 web.config 文件。也许 EF 升级无法在没有生成无效 xml 文档的情况下写入它们。

    【讨论】:

      【解决方案4】:

      这与您的配置文件有关。只是详细说明我找到的解决方案:

      首先保存你的 app.config、packages.config 和 web.config

      然后将它们全部删除。我实际上删除了 app.config 和 packages.config,只是清除了 web.config 之间的行。

      然后我再次运行 Install-Package,一切顺利,然后我重新添加到我的配置中。

      【讨论】:

      • 我不得不将app.config和web.config移动到不同的目录,创建一个空的app.config文件,然后手动将新生成的数据合并到现有的配置文件中。 (大多数情况下,生成的数据是相同的。)
      【解决方案5】:

      在 Web 应用中,web.config 引用了外部 app.config:

      &lt;appSettings configSource="App.config" /&gt;

      这要求 App.config 采用特定格式,EntityFrameworks 安装程序认为无效

      所以,和其他人一样,关键是:

      • 重命名/删除 App.config

      • 安装 EF

      • 恢复 App.config

      【讨论】:

      • 这解决了我将 EF6 安装到旧版应用程序的问题。我从 web.config 中删除了 xmlns,但也不得不暂时重命名 app.config 以使其正常工作。 app.config 中没有任何明显的原因导致此问题。
      【解决方案6】:

      我遇到了同样的问题,我从

      修改了我的 web.config
      (<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">)
      

      到

      (<configuration>)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多