繁体   English   中英

EntityFramework.dll中出现“System.Xml.XmlException”类型的异常,但未在用户代码中处理

[英]An exception of type 'System.Xml.XmlException' occurred in EntityFramework.dll but was not handled in user code

编程新手,对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:         }

每个视图都会发生这种情况。 我已经尝试过搭建一个新的教师,但是再一次,但是在任何生成的视图上都会出现错误。

当我尝试在Package Management控制台上运行update-database时,我也遇到了同样的错误:

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.

昨天一切都很好。 我今天进来并开始使用我的机器,从那时起就遇到了这个问题。 我绝对不知道自己出了什么问题,只是不明白为什么现在这样。 检查了许多其他没有帮助的线程。

谢谢你的帮助。

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

谢谢大家

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM