1

One of our development machines is giving an error saying that DbContext does not implement IDisposable. According to a similar SO post, this is because we are not referencing EF 5. The problem assembly has a *.edmx file built with older EF 4 constructs (ObjectContext). This same assembly also has a newly added *.edmx file with the newer constructs (DbContext).

A different project on a different machine also uses DbContext and works fine. Said project shows the following information for EntityFramework.dll:

version:  4.4.0.0
Runtime Version:  v4.0.30319

I checked the bad build machine and it also has this same version of EntityFramework.dll.

Microsoft has had confusing conflicts between development and marketing version naming conventions. So does EF 5 mean the dll version should say 5.0?

In other words, am I running v4.0 on the good build machine? If so why is the build successful?

Community
  • 1
  • 1
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
  • 3
    EF **4.4** = EF 5 on .NET 4.0. EF **5.0** = EF 5 on .NET 4.5. Confusing? Yes - but that's Microsoft marketing hard at work :-) And to make it even more confusing: **some features** of EF 5 will only work if you target **.NET 4.5** (but not on .NET 4.0) – marc_s Aug 08 '13 at 16:23

1 Answers1

6

The Entity Framework v5.0 dll is dependent on the .NET CLR you are targeting. If your project is set to use the .NET 4.0 framework, the runtime version of the EntityFramework.dll will be 4.4.0.0.

If you are using Entity Framework with a CLR target of .NET 4.5, the version of the EntityFramework.dll will be 5.0.

When you add EntityFramework via nuget, it will look at your project's CLR target runtime and add the appropriate EntityFramework.dll reference. If you later change your target, you should uninstall and reinstall the EntityFramework reference via nuget to make sure that the correct version of the runtime is referenced by your project.

Reference post by Julie Lerman about the topic.

codechurn
  • 3,870
  • 4
  • 45
  • 65
  • Very helpful! If that's true, why does the build fail? Remember, runtime version is 4.0 on both machines. – P.Brian.Mackey Aug 08 '13 at 16:23
  • Have you added EntityFramework via nuget? If so, it is possible that the cached version in the packages folder is perhaps out of sync and/or not present in version control when the build server does a get. When you are doing a build, the server might be falling back to the legacy version of EntityFramework which was included in .NET 3.5 (which did not include DbContext) when it attempts to resolve the reference because the EF5 binaries are not present. I would take a look and make sure the build server can properly resolve all references for EF. – codechurn Aug 08 '13 at 16:28
  • This project is old and created by someone else. Your answer makes perfect sense. We will reinstall via nuget. – P.Brian.Mackey Aug 08 '13 at 16:31