30

Installed visual studio 11 beta as wanted to test EF 5 beta but keep hitting this an error.

Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.

Project is a new blank MVC3 application and below is some code that illustrate how the error happens.

public class Blog
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class EFDbContext : DbContext
{
    public DbSet<Blog> Blogs { get; set; }
}

public class HomeController : Controller
{
    protected EFDbContext Db = new EFDbContext();

    public ActionResult Index()
    {
        Blog B = new Blog();
        B.Name = "Test";            
        Db.Blogs.Add(B);
        Db.SaveChanges();
        return View();
    }
}

Looked for the error on google but nothing came up and i'm not quite sure what error is referring to. I added a snippet of the stacktrace below in case it will help.

[MissingMethodException: Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.] System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +0 System.Data.Entity.Internal.InternalContext.Initialize() +31
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +39
System.Data.Entity.Internal.Linq.InternalSet1.Initialize() +137
System.Data.Entity.Internal.Linq.InternalSet
1.get_InternalContext() +38 System.Data.Entity.Internal.Linq.InternalSet1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +236
System.Data.Entity.Internal.Linq.InternalSet
1.Add(Object entity) +200 System.Data.Entity.DbSet`1.Add(TEntity entity) +72

Drauka
  • 1,217
  • 2
  • 10
  • 21

4 Answers4

60

Looks like you are using the EF5 EntityFramework.dll but then running with .NET 4 installed instead of .NET 4.5.

If you are intending to target .NET 4.5, then make sure that .NET 4.5 is installed on the machine on which you are running the code. VS11 installs .NET 4.5 for you, but you can also install just the runtime on a non-dev machine.

If you are intending to target .NET 4, then make sure that you project is set to target .NET 4 and then uninstall and reinstall the EF5 NuGet package. You must uninstall and reinstall because NuGet won't change the assembly in use automatically when the project is re-taregted.

Update:

You may also see this exception if you still have the EF June CTP installed or if it failed to uninstall correctly. Please try to uninstall the June CTP fully before installing VS11. If you still see problems them open a "Developer Command Prompt" as Administrator and run:

gacutil /u System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089

If this still fails, then you can attempt to force the uninstall from the GAC with:

gacutil /uf System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089
Arthur Vickers
  • 7,503
  • 32
  • 26
  • Appreciate the response. However I have .Net 4.5 installed and my project is targeting the .net 4.5 framework as well. I was attempting to run EF 5.0 beta in VS 11 Ultimate Beta with .Net 4.5 Beta framework. I will try to uninstall VS11 and .Net 4.5 framework and start over. – Drauka Mar 07 '12 at 21:06
  • Uninstalled vs11 beta and the 4.5 framework and reinstalled vs11 beta including 4.5 .... The problem persists and I'm getting the same error. – Drauka Mar 07 '12 at 22:52
  • Can you find file version of System.Data.Entity.dll in the GAC? In Windows Explorer, open the folder C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.0.0.0__b77a5c561934e089 or the equivalent on your machine. Right click on System.Data.Entity.dll, select the Details tab, and look at the Product version. If it is "4.0.30319.17379" then you have .NET 4.5 installed. If it is "4.0.30319.1" then you somehow still have .NET 4 installed. – Arthur Vickers Mar 07 '12 at 23:32
  • I actually have 2 folders under 'system.data.entity' 1. C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.0.0.0__b77a5c561934e089 2. C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Data.Entity\v4.0_4.2.0.0__b77a5c561934e089 dll in folder 1. has product version: 4.0.30319.17379 dll in folder 2. has product version: 4.0.30319.0 Tried to remove the folder 2 but that causes an error and to be honest I don't have much experience messing around with the DLL's like this so any further advice is much appreciated. – Drauka Mar 08 '12 at 00:01
  • Have you now or have you ever had the EF June CTP installed on that machine? If so, make sure that it is fully uninstalled and that your project is targeting .NET 4.5 and not the "Microsoft Entity Framework June 2011 CTP". You may also need to re-install VS again after uninstalling the CTP. – Arthur Vickers Mar 08 '12 at 00:12
  • I have had the June CTP installed but I've removed that before I installed vs11 beta earlier today. – Drauka Mar 08 '12 at 00:21
  • 1
    If that assembly is in the GAC, then it didn't get uninstalled fully. Can you open a Developer Command Prompt as Administrator and run "gacutil -l System.Data.Entity" then let me know what it reports? – Arthur Vickers Mar 08 '12 at 00:29
  • reports that it has 3 items: version=3.5.0.0 version=4.0.0.0 version=4.2.0.0 – Drauka Mar 08 '12 at 00:38
  • Can you try running "gacutil /u System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" from the Developer Command Prompt as Administrator? If that doesn't work, try "gacutil /uf System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" – Arthur Vickers Mar 08 '12 at 00:48
  • 1
    success ... removing the framework from JUNE CTP worked. Just wish that would have worked out of the box when i uninstalled it :s Thank you very much for your help. – Drauka Mar 08 '12 at 00:52
  • Is this still up to data? Got here through googling this error I got after uploading my project. When using VS express 2012 for web and chosing file => new project => mvc 3 application (setting .net framework to version 4 not 4.5). After creating the project there is an EntityFramework.dll file. Right click that file => properties => details gives me "product version 5.0.0 .net 4.0). Suggesting that EF 5 can work with .net 4. – HMR Apr 09 '13 at 04:57
5

Make sure you have .net 4.5 installed on your target system. I had the same message, turned out I didn't have .net 4.5 installed on one of my farm servers.

ddd
  • 51
  • 1
  • 1
0

If you have trouble getting rid of the 4.2 System.Data.Entity from the GAC like I did, where it complained the installer depended on it,

G:\Program Files (x86)\Microsoft Visual Studio 2012 Ultimate\VC>gacutil /uf System.Data.Entity,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.17929
Copyright (c) Microsoft Corporation.  All rights reserved.


Assembly: System.Data.Entity, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b
77a5c561934e089, processorArchitecture=MSIL
Assembly could not be uninstalled because it is required by Windows Installer
Number of assemblies uninstalled = 0
Number of failures = 0

you can get rid of the keys in the registry from this folder:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Installer\Assemblies\Global

and rerun the gacutil /uf command

aggaton
  • 3,066
  • 2
  • 25
  • 36
0

I solved this problem removing the policy:

C:\Windows\Microsoft.NET\assembly\GAC_MSIL\policy.4.0.system.data.entity\v4.0_0.0.0.0__b77a5c561934e089\policy.4.0.system.data.entity.config

Which had this information: ... bindingRedirect oldVersion="4.0.0.0" newVersion="4.2.0.0" ...

Hope it helps Rui

rsantos
  • 230
  • 1
  • 15