1

update-database他のマシンで実行される Entity Framework 5 プロジェクトで実行しようとしています。

コードをダウンロードし、プロジェクトを再構築しました。実行するupdate-databaseと、次のようなエラーが発生します。

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindType[TBase](String typeName, Func`2 filter, Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
   at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

このエラーは、私の環境に一部のアセンブリが見つからないか、GAC で互換性のないアセンブリが見つかったために発生していると思います。しかし、どのタイプがロードに失敗したかを知らずに、私は暗闇の中にいるので、デバッグするのは非常に難しい問題です.

読み込みに失敗した型またはアセンブリを確認するにはどうすればよいですか? メッセージには「詳細については LoaderExceptions プロパティを取得してください」と書かれていますが、移行が自分のコードではなくパッケージ マネージャー コンソールで実行されている場合、どうすればそれを実行できますか?

コンソールに入力$Error[0].Exceptionすると例外メッセージが表示されますが、他のプロパティを一覧表示するにはどうすればよいですか?

4

1 に答える 1

3

参考になるかどうかわかりませんが、アイデアを投げるだけです...

コードから移行を実行してみると、例外処理が改善される可能性があります。例えば

ナゲットなしのEFコードファーストDbMigration

DbMigrator migrator = new DbMigrator(new YourConfiguration());
migrator.Update(); // or update specific migrations..    

構成を介してそれを有効にすることもできます-再コンパイルせずに有効にすることもできます(本番用)-ロギング/トレースを有効にすると、エラーが発生する可能性があります...

    <contexts>
        <context type="YourNS.YourContext, YourAssembly">
            <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[YourNS.YourContext, YourAssembly], [YourNS.YourConfiguration, YourAssembly]], EntityFramework" />
        </context>
    </contexts>

</entityFramework>
于 2013-04-03T14:03:38.970 に答える