![](/img/trans.png)
[英]An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code
[英]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.