System.Xml.XmlException'在EntityFramework.dll中发生,但未在用户代码中

本文关键字:代码 用户 dll XmlException Xml EntityFramework System | 更新日期: 2023-09-27 18:15:08

编程新手,stackoverflow新手,如果这不是一个合适的问题,那么很抱歉。我得到一个错误信息,我完全惊呆了,我的程序出了什么问题。

基本上,每当我尝试调用视图时,我都会得到标题中描述的错误。我的程序失败的一些例子:

Line 22:         public ActionResult Index()
Line 23:         {
**Line 24:             return View(db.hostSystems.ToList());**
Line 25:         }
Line 26: 

下面是一个不同的例子:

Line 20:         public ActionResult Index()
Line 21:         {
**Line 22:             var hostDocuments = db.hostDocuments.Include(b => b.hostSystem);**
Line 23:             return View(hostDocuments.ToList());
Line 24:         }

这发生在每个视图上。我尝试脚手架一个新的讲师,但是,再次,但错误发生在任何生成的视图。

当我尝试在包管理控制台上运行更新数据库时,我也会得到相同的错误:

PM> update-database -Force
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201610121010400_InitialCreate, 201610141128247_NewFields, 201610141215392_changes, 201610141223280_changes2].
Applying explicit migration: 201610121010400_InitialCreate.
System.Xml.XmlException: Syntax for an XML declaration is invalid. Line 1, position 21.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl)
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
   at System.Xml.Linq.XDocument.Load(Stream stream, LoadOptions options)
   at System.Data.Entity.Migrations.Edm.ModelCompressor.Decompress(Byte[] bytes)
   at System.Data.Entity.Migrations.DbMigration.GetModel(Func`2 modelAccessor)
   at System.Data.Entity.Migrations.DbMigration.GetTargetModel()
   at System.Data.Entity.Migrations.DbMigrator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.ApplyMigration(DbMigration migration, DbMigration lastMigration)
   at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
   at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
   at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
   at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
Syntax for an XML declaration is invalid. Line 1, position 21.

昨天一切都很好。我今天进来,开始使用我的机器,从那以后就一直有这个问题。我完全不知道什么是错的,只是不明白为什么现在会发生这种情况。我检查了许多其他没有帮助的线程。

感谢您的帮助

System.Xml.XmlException'在EntityFramework.dll中发生,但未在用户代码中

最后是由于损坏的迁移。我还在调查这个问题,但它已经解决了。

谢谢所有的