2016-10-27 9 views
1

プログラミングに新しく、stackoverflowに新しく、これは適切な質問ではない場合はお詫び申し上げます。エラーメッセージが表示されているので、私のプログラムに何が間違っているのか全く唖然としています。EntityFramework.dllで 'System.Xml.XmlException'型の例外が発生しましたが、ユーザーコードで処理されませんでした。

基本的には、ビューを呼び出そうとすると、タイトルに記述されているエラーが発生します。私のプログラムが失敗した場合のいくつかの例:これは、すべての単一のビューで何が起こっている

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

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

以下は異なる例です。私は新しいインストラクターを足かせにしようとしましたが、もう一度やりましたが、生成されたビューでエラーが発生します。

私はパッケージ管理コンソール上で更新するデータベースを実行しようとすると、私も同じエラーが出ます:

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. 

すべてが昨日罰金働いていました。私は今日来て、私のマシンを使い始めて以来、この問題を抱えていました。私は何が間違っているかについて自分自身に絶対にあり、なぜこれが今起こっているのか理解できません。役に立たなかった多くのスレッドをチェックしました。

ありがとうございました。

+1

コールスタックの指定された移行コードが表示されているはずです。問題はそれらの中にある。 – mybirthname

+1

初期のEFコードの最初の移行で何か問題があるように見えます。あなたは4つのマイグレーションを持っており、最初のものに転倒しています – uk2k05

+1

XML宣言の構文が無効です:XMLファイルを昨日から今日まで編集しましたか?破損したファイルがあると思われます。 XmlExceptionは、1つの要素が使用できない場合にも発生します。 – Sebi

答えて

0

最後に、移行の破損が原因でした。私はまだ問題を調査中ですが、解決されています。

ありがとうございました

関連する問題

 関連する問題