问题
I'm trying to run update-database
in an Entity Framework 5 project that runs on other machine.
I downloaded the code, rebuilt the project and when I run update-database
I get an error like this:
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.
I assume that this error is happening because some assembly is missing on my environment, or maybe because of an incompatible assembly being found in the GAC. But whitout knowing wich type failed to load, I'm in the dark so it's a very difficult issue to debug.
How can I find out which type or assembly failed to load? The message says to "retrieve the LoaderExceptions property for more information" but how can I do that, given the migration runs in the package manager console, and not in my own code?
Typing $Error[0].Exception
in the console shows the exception message, but how can I list its other properties?
回答1:
I'm not sure if this could help you, but just throwing an idea...
You could try running the migration from the code - there you might get beter exception handling. e.g.
EF Code First DbMigration without nuget
DbMigrator migrator = new DbMigrator(new YourConfiguration());
migrator.Update(); // or update specific migrations..
You could also turn that via config - and even turn that on w/o recompiling (for production) - if you have logging/tracing enabled you might get some errors from it...
<contexts>
<context type="YourNS.YourContext, YourAssembly">
<databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[YourNS.YourContext, YourAssembly], [YourNS.YourConfiguration, YourAssembly]], EntityFramework" />
</context>
</contexts>
</entityFramework>
来源:https://stackoverflow.com/questions/15774247/how-to-debug-entity-framework-migration-loaderexceptions