2013-04-02 4 views
1

update-database을 다른 컴퓨터에서 실행되는 Entity Framework 5 프로젝트에서 실행하려고합니다. Entity Framework 마이그레이션을 디버깅하는 방법 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을 입력하면 예외 메시지가 표시되지만 다른 속성은 어떻게 나열 할 수 있습니까? 이 당신을 도울하지만, 단지 아이디어를 던져 수 있다면

+0

예외를 System.Reflection.ReflectionTypeLoadException에 캐스팅하고 LoaderExceptions 속성에 액세스하려고 했습니까? – user1908061

+0

@ user1908061 아니, 어디에서해야합니까? PowerShell 명령 줄에서? 수업 파일에? 방법? 이것은 대답 일 수 있습니다.이 경우 좀 더 자세하게 답변을 게시하면 감사하겠습니다. –

+0

'$ Error [0] .Exception'으로했던 것처럼 콘솔에 타이핑하지만, 이번에는 Exception을 올바른 타입으로 캐스팅하고 정확한 문제에 관한 더 많은 정보를 얻기 위해'LoaderExceptions' 속성에 접근합니다. 그러나 당신이 이미 문제를 해결했기 때문에 기쁩니다. :-) – user1908061

답변

3

는 잘 모르겠어요 ...

당신은 코드에서 마이그레이션을 실행 시도해 볼 수도 있습니다 - 거기 당신은 BETER 예외 처리를 얻을 수 있습니다. 예 : 심지어 (생산) 재 컴파일하여 w/o에 그 설정 - -

EF Code First DbMigration without nuget

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> 
+0

내 마이그레이션 프로젝트를 참조하고 게시 한 코드가 포함 된 새로운 콘솔 응용 프로그램 프로젝트를 만들었습니다. 그것이 실행되었을 때 예외를보고 어떤 어셈블리가로드되지 않았는지 확인할 수있었습니다. 고맙습니다. –

+1

나는 그것이 잘 될지 전혀 몰랐다. 그러나 그렇게 기뻤다. :) 오신 것을 환영합니다. @ FernandoCorreia – NSGaga

관련 문제