如何调试实体框架迁移LoaderExceptions? [英] How to debug Entity Framework migration LoaderExceptions?

查看:109
本文介绍了如何调试实体框架迁移LoaderExceptions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在其他计算机上运行的Entity Framework 5项目中运行更新数据库

I'm trying to run update-database in an Entity Framework 5 project that runs on other machine.

我下载了代码,重建了项目,当我运行 update-database 时,出现如下错误:

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.

我认为发生此错误是因为我的环境中缺少某些程序集,或者可能是由于GAC中发现不兼容的程序集。但是,尽管知道类型无法加载,但我还是处于黑暗之中,因此调试起来非常困难。

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.

我如何找出哪种类型或程序集无法加载加载?该消息说要获取LoaderExceptions属性以获取更多信息,但是鉴于迁移是在程序包管理器控制台中而不是在我自己的代码中运行的,我该怎么做?

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?

在控制台中键入 $ Error [0] .Exception 会显示异常消息,但是如何列出其其他属性?

Typing $Error[0].Exception in the console shows the exception message, but how can I list its other properties?

推荐答案

我不确定这是否对您有帮助,只是抛出一个主意...

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代码优先DbMigration,不包含nuget

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

您也可以通过config来启用它-甚至打开它不进行重新编译(用于生产)-如果启用了日志记录/跟踪,则可能会从中获取一些错误...

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>

这篇关于如何调试实体框架迁移LoaderExceptions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆