I'm using EntityFramework but in some cases I get this Exception:
threw an exception.", inner exception: "Method not found: 'Void System.Data.Entity.DbModelBuilder.RegisterEntityType(System.Type)'.
Why is this exception is happening?
As I found out, this exception is happening when system expected to have EF 6.1.3, but the referenced EF is 6.0.0. As I updated my EF via nuget, it worked. The problem is in some cases I can not found any 6.0.0
For example I'm using a 3rd party component (XAF) which have a designer in Visual Studio. The designer cannot load because of this exception. The EF in my project is 6.1.3 but I don't know how it uses 6.0.0
Question 1: Why and when is this exception happening?
This exception probably is happening because of the different versions of loaded assemblies. If XAF referencies the 6.0.0 version in it's metadata, and your project doesn't, the compiler will load the 6.0.0 version to bin folder.
You can try overload the assembly version in you application configuration file (app.config), using something like this:
<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>