51

I've got one solution - the one project is class library with .edmx data model The other is asp.net web forms project.

when i start the solution I get the following exception:

The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

and when I see the references in my asp.net project I see the reference to my class and I can't see reference to entity framework. But the problem is that entity framework is installed both in my class library and web project

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Tania Marinova
  • 1,788
  • 8
  • 39
  • 67
  • *I can't see reference to entity framework. But the problem is that entity framework is installed ... in my ... web project* Remove the NuGet package and add it again. – ta.speot.is Sep 28 '13 at 07:31

10 Answers10

65

I think your EntityFramework version was confused

Please download the correct version by using the NuGet package installer.

See this discussion for getting started: The type or namespace name 'DbContext' could not be found

And look this same problem and Answer : is Here

Community
  • 1
  • 1
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • 2
    Thanks, that help me. The reason is: My `entityframework.dll` declared in my `packages.config` file was `5.0.0` and this version doesn't have the type `DbContext`, now I updated the version (with my nuget) to the version `6.0.0` and now it's working. – Benjamin RD Jan 21 '16 at 21:28
  • I used NuGet package manager in VS. Uninstall EF from the project and then install it again. Shrug. – Jess Feb 14 '19 at 15:23
11

I found this solution suitable for me.

Adding Entity Framework DLL Reference:-

  1. Go to c:\Program Files (x86)\Microsoft ASP.NET\ASP.NETMVC 4\Packages\EntityFramework 5.0.0-rc\lib\net45

  2. Add Entity framework DLL

Mazhar Khan
  • 396
  • 4
  • 15
  • 1
    I also had to add `EntityFramework.SqlServer` from the same location, which in my case was MVC5 instead of MVC4. – toddmo Dec 07 '16 at 17:11
6

I suggest you to check:

Allow NuGet to download missing packages during build ticked please refer this link

Community
  • 1
  • 1
Thilina H
  • 5,754
  • 6
  • 26
  • 56
  • The latest version of NuGet has this on by default. Also, I take issue with @Maris calling this a "workaround". It's part of the process of using NuGet if you want to avoid checking packages in to your SCM. – ta.speot.is Sep 28 '13 at 10:34
6

If someone has more than one project, you need to install it to the projects that require it. Also what helped me was changing the default project and then installing via package manager console and that resolved it.

Harry
  • 3,031
  • 7
  • 42
  • 67
2

I had the same problem and I finally solved it. what you should do is to uninstall every instance of entity framework on your pc. If you have installed it using the setup file you have to remove it from add/remove programs and if you have installed it using the nugget packages, you have to uninstall it from there.

Then you install in again using the nugget packages and restart your visual studio. This solved my problem.

  • This saved me. Just to clarify though, I just needed to remove all instances from my project. In my scenario, I was trying to port from .net to .net core and this solution worked for me. – Jamieson Rhyne Jun 29 '17 at 19:51
2

Do this, it will solve the issue as it seems you have not installed Entity Framework properly or it is not working properly, Go to TOOLS > Library Package Manager > Package Manager Console in VS2012 and typed install-package EntityFramework

Manoj Kargeti
  • 161
  • 13
0

I ran into this problem when I pulled a project from SVN to a new computer. Installing Entity Framework via NuGet solved the problem. I installed the most current version which is now 6.1.1

Bruno
  • 533
  • 1
  • 6
  • 27
  • I did this and I stillhave the problem – Bastien Vandamme Jul 31 '14 at 09:34
  • If you have more than one project, did you install the nuget package on all the projects that need it? Also, have you double checked the dll path in the Entity Framework reference to make sure it's correct? – Bruno Jul 31 '14 at 13:34
0

I already had the correct version of the entity framework DLL, and none of the other answers here worked for me: I had to select the EntityFramework reference in the project, then in the properties, set "Specific Version" to true.

Graham Laight
  • 4,700
  • 3
  • 29
  • 28
0

The error message is telling you that the class library with .edmx data model has the Entity Framework 5 loaded ... (obviously because there are no error messages in the .edmx) ... and your web project is referencing the class library ... so it has access to everything in the class library ... but it cannot handle the data types in the class library because your web project needs a reference to the Entity Framework 5. You will also notice that your intellisense doesn't work for the objects in your class library either.

Simply add a reference in your web project to the entity framework 5 ... and your all set.

Marc Johnston
  • 1,276
  • 1
  • 7
  • 16
0

Add the correct reference in *.csproj file. in my cas i have added below in *.csproj file and problem solved.

 <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
      <Private>True</Private>
    </Reference>
Kumod Singh
  • 2,113
  • 1
  • 16
  • 18