6

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?

Community
  • 1
  • 1
Olaf
  • 10,049
  • 8
  • 38
  • 54
  • @hvd, thanks for the hin. But that refers to the development process, doesn't it, and here everything is sound. After all, it runs on another server, just not on our backup instance. – Olaf Jan 20 '14 at 12:51
  • Ah, sorry, I missed that bit. You're right, if the exact same website runs on one server, and doesn't on another, my comment cannot be of help. –  Jan 20 '14 at 13:26
  • Wait - no, it can still be relevant. If you use the .NET 4.5 version of Entity Framework in a .NET 4.0 project, it will work, so long as you run it on a system that has .NET 4.5 installed. You'd only start getting errors when you run in on a server that doesn't have it. –  Jan 20 '14 at 13:28
  • @hvd - interesting thought, you are right. I believe .NET 4.5 isn't installed on the primary server either, but it might be worth trying to install 4.5. Thanks again. – Olaf Jan 20 '14 at 13:37

1 Answers1

4

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...

DZx
  • 347
  • 1
  • 4
  • 11