我一直在尝试安装实体框架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?
注意:它只会安装到类库而不是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
答案 0 :(得分:18)
我遇到了同样的问题。事实证明,我正在为我的一个旧项目添加EF,而web.config已为<configuration />
元素定义了此命名空间:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
删除该命名空间声明(xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"
)有助于解决此问题。
答案 1 :(得分:5)
我遇到了同样的问题,发现原因是web.config文件中的元素。就我而言,我改变了这个:
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
到此:
<configuration>
修正了它。
答案 2 :(得分:2)
升级Entity Framework后,app.config或web.config文件会将内容写入其中。我怀疑可能是问题所在。看看你的app.config或web.config文件。也许EF升级在写入它们时没有制作无效的xml文档。
答案 3 :(得分:2)
这与您的配置文件有关。只是详细说明我发现的解决方案:
首先保存您的app.config,packages.config和web.config
然后全部删除它们。我实际上删除了app.config和packages.config,并清除了web.config之间和之间的界限。
然后我再次运行Install-Package,一切顺利,然后我在我的配置中添加了。
答案 4 :(得分:1)
在Web应用程序中,web.config引用了外部app.config:
<appSettings configSource="App.config" />
这要求App.config采用特定格式,即EntityFrameworks安装程序认为无效
所以,和其他人一样,关键在于:
重命名/删除App.config
安装EF
带回App.config
答案 5 :(得分:0)
我遇到了同样的问题,我从
修改了我的web.config(<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">)
要
(<configuration>)