我試圖在其他機器上運行的Entity Framework 5項目中運行update-database
。如何調試實體框架遷移LoaderExceptions?
我下載的代碼,重建項目,當我運行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
顯示異常消息,但是如何列出其他屬性?
您是否嘗試將異常轉換爲System.Reflection.ReflectionTypeLoadException並訪問LoaderExceptions屬性? – user1908061
@ user1908061不,我應該怎麼做?在PowerShell命令行中?在類文件中?怎麼樣?這可能是答案,在這種情況下,如果您將它作爲一個更詳細的答案發布,我會很感激。 –
我把它在控制檯中輸入,就像你用'$ Error [0] .Exception'所做的那樣,但是這次把異常轉換爲正確的類型並訪問'LoaderExceptions'屬性來獲得更多有關確切問題的信息。但我很高興你已經解決了這個問題。 :-) – user1908061