Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

On a Windows 2008 R2, running on a Virtuozzo Virtual Machine, an ASP.NET MVC 4 web using Entity Framework throws the exception

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

An identical web with the same web.config is running fine on another (root) server with Windows 2012 and of course locally in the development environment.

We are using .NET 4.0. The top of the stack trace is as follows:

[MissingMethodException: Method not found: 'Void System.Data.Objects.ObjectContextOptions.set_UseConsistentNullReferenceBehavior(Boolean)'.] System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +0 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(String sql, Object[] parameters) +34 System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerable(String sql, Object[] parameters) +91 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(Type elementType, String sql, Object[] parameters) +250 System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() +34 System.Data.Entity.Internal.InternalSqlQuery1.GetEnumerator() +28 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +382 System.Linq.Enumerable.ToList(IEnumerable1 source) +80 [...]

I did all that's suggestes in Can anyone spot why I keep getting this error testing the EF 5 beta. There are no traces of an old EF beta. I re-installed .NET 4.

The error is rare on Google.

What else can I try?

like image 767
Olaf Avatar asked Jan 20 '14 12:01

Olaf


1 Answers

I ran into this as well, and the issue was that Entity Framework versions 4.1 and 5 are both installed on my workstation. This particular program needed to be installed on a server that runs .Net 4, but not 4.5. (For other reasons, we cannot upgrade the server.) However, by default, when I added the ADO.Net Entity Data Model to my project, Visual Studio added a reference to EF version 5.

By deleting the EF reference and manually adding it back as version 4.1, it ran successfully on the server.

You may have already solved this by installed .Net 4.5 on your server...

like image 195
DZx Avatar answered Nov 11 '22 01:11

DZx