EF 6 System.Data.Objects.ObjectContext Error

asp.net-mvc asp.net-mvc-4 azure-sql-database c# entity-framework-6


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?

1/30/2013 8:28:34 AM

Accepted Answer

EF 6 does not have System.Data.Objects.ObjectContext. EF 6 has moved some types, including ObjectContext, from System.Data.Entity.dll into EntityFramework.dll, and changed their namespaces. The fact that you get this error suggests you haven't attempted to recompile your application, you've simply replaced EntityFramework.dll and hoped for the best. That won't work. You need to update your code to work with EF 6: you need to remove your references to System.Data.Entity.dll, and update your code to refer to the new types.

It just might be possible for the reference to the IObjectContextAdapter.ObjectContext property to be in some library you're using, but most likely it'll be in your own code. The error message (in the part you didn't include in your question) should tell you where it is coming from.

1/1/2013 10:53:47 PM

Popular Answer

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;

Related Questions


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