简体   繁体   中英

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

New to programming, new to stackoverflow, so apologies if this is not an appropriate question. I am getting a error message and I am completely dumbfounded as too what is wrong with my program.

Basically, whenever I try to call a view, I get the error as described in the title. Some examples of where my program is failing:

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

Below is a different example:

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:         }

This is happening on every single view. I have tried to scaffold a new instructor, but again, but the error occurs on any generated views.

I also get the same error when I try to run an update-database on the Package Management console:

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.

Everything was working fine yesterday. I came in today and started to use my machine and have had this problem ever since. I am absolutely besides myself on what is wrong, and just can't understand why this is now occurring. Have checked many other threads that haven't helped.

Thank you for any assistance.

In the end it was due to a corrupted migration. I am still investigating the problem, but it is solved.

Thanks all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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