2015-10-05 57 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包。

相关问题