Method not found: 'Void System.Data.Entity.DbModelBuilder.RegisterEntityType(System.Type)'

c# entity-framework entity-framework-6

Question

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?

1
3
10/5/2015 5:07:59 PM

Popular Answer

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>
4
10/5/2015 5:17:30 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow