EF 6 System.Data.Objects.ObjectContext Error

60,038

Solution 1

For me updating these below worked:
using System.Data.Objects; --> using System.Data.Entity.Core.Objects;

using System.Data.Objects.DataClasses; --> using System.Data.Entity.Core.Objects.DataClasses;

Solution 2

I'm also using EF 6.

I managed to solve the problem uninstalling the package Microsoft.AspNet.Providers.Core v. 1.2. I'm using version 1.1 instead. If you're like me and is using LocaDb, you'll have to uninstall the LocaDb package because it depends on that package. Of course you'll have to reinstall LocaDb again...

You can grab v. 1.1 using the NuGet Package Manager Console inside Visual Studio:

Install-Package Microsoft.AspNet.Providers.Core -Version 1.1

There's a Microsoft Connect bug filled regarding this issue:

Microsoft.AspNet.Providers.Core incompatible with EF6

Solution 3

The new 2.0 version of the providers (http://www.nuget.org/packages/Microsoft.AspNet.Providers.Core/) are EF6 compatible (they'll actually only work with EF6).

Solution 4

I managed to resolve this by removing the AspNet Providers I had installed through Nuget, which was marked as deprecated. Doing this also uninstalled Entity Framework.

I then installed the new AspNet Universal Providers, followed by Entity Framework 6, and all my problems were fixed.

Solution 5

It has an old version associated with edmx file for this:

  • Reinstall EF with Nuget
  • Delete the .edmx file and recreate it with tables
Share:
60,038
Joe
Author by

Joe

Updated on July 06, 2020

Comments

  • Joe
    Joe almost 4 years

    I recently upgraded from Entities Framework 5 to Entities Framework 6 Alpha 2 and I am getting the following error:

    Method not found: 'System.Data.Objects.ObjectContext System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()'.

    This is getting hit when I call

    if (Membership.ValidateUser(model.UserName, model.Password)) {}
    

    This used to work fine before not sure why it's springing this error. Any suggestions?

  • Roger
    Roger over 10 years
    Unfortunately, this didn't work for me. I am getting the same error as the thread author except the stack trace shows it coming from System.Web.Providers.ModelHelper.EnsureDatabaseCreated, which is getting called by System.Web.Providers.DefaultRoleProvider.GetRolesForUser.
  • Gleno
    Gleno over 10 years
    The new Providers? You mean 1 year old version 1.2? Or am I missing something?
  • Eraph
    Eraph over 10 years
    I may be a bit behind the times :)
  • Gleno
    Gleno over 10 years
    Well, then, I'll report that 1.2 doesn't work. 1.1. Seems to work for now.
  • Leniel Maccaferri
    Leniel Maccaferri over 10 years
    @Roger: I did not delete your answer. I have enough reputation to see your deleted answer. I just copied and pasted the link in my answer because I thought that could be helpful. I think your answer was deleted by the community because it had 1 link only and when an answer gets down voted it goes to a pool (Reviews section here at SO) for others to review and decide if it should be closed. Hope it helps you understand what happened.
  • Roger
    Roger over 10 years
    OK. So I guess it's frowned upon to post a link like I did, even when relevant? I don't really understand that.
  • Leniel Maccaferri
    Leniel Maccaferri over 10 years
    @Roger: when you want to share a link like that it's recommended that you put a comment under the question or an existing answer. See here for more info about deleted answers: stackoverflow.com/help/deleted-answers "barely more than a link to an external site"
  • Anthony Mason
    Anthony Mason almost 8 years
    This is a good idea in general if that is the targeted framework, but it does not directly address the issue. For me, I simply modified the Context.tt template file to exclude the older assemblies and include using System.Data.Objects. I am not sure that this would resolve the issues for anyone else here. Now if you uninstall the NuGet packages, upgrade framework, then install the new NuGet packages, I can see that working.
  • user1069816
    user1069816 over 7 years
    The Microsoft Connect link is now dead.
  • Baljeetsingh
    Baljeetsingh over 6 years
    for me I had EF6 via Nuget . I installed 5.00 to the web project and it worked.