2015-10-05 53 views
0

我使用的EntityFramework,但在某些情況下,我得到這個異常:方法:「無效System.Data.Entity.DbModelBuilder.RegisterEntityType(System.Type的)」

threw an exception.", inner exception: "Method not found: 'Void System.Data.Entity.DbModelBuilder.RegisterEntityType(System.Type)'. 

這是爲什麼例外是發生了什麼?

正如我發現的,當系統預計有EF 6.1.3,但引用的EF是6.0.0時,會發生此異常。 當我通過nuget更新我的EF時,它工作。問題是在某些情況下,我找不到任何6.0.0

例如我使用的第三方組件(XAF)在Visual Studio中有一個設計器。 由於此例外,設計者無法加載。我項目中的EF爲6.1.3,但我不知道它如何使用6.0.0

問題1:爲什麼以及何時發生此異常?

回答

1

由於加載的程序集版本不同,可能會發生此異常。如果XAF引用了元數據中的6.0.0版本,而您的項目沒有,編譯器會將6.0.0版本加載到bin文件夾中。

你可以嘗試在你的應用程序配置文件(app.config)中重載集版本,使用這樣的事情:

<configuration> 
    <runtime> 
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
      <dependentAssembly> 
       <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> 
       <bindingRedirect oldVersion="0.0.0-6.0.0" newVersion="6.1.3" /> 
      </dependentAssembly> 
     </assemblyBinding> 
    </runtime> 
</configuration> 
0

我在所有的app.config和網絡有同樣的問題,換版EF的.config文件更正版本。像這樣在我的數據層prject的的app.config:所有的項目都使用相同版本

<configSections> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.1.3.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 

,還可以管理我的NuGet包。

相關問題