The type 'System.Data.Entity.DbContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'EntityFramework 2

.NetEntity Framework

.Net Problem Overview


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

.Net Solutions


Solution 1 - .Net

I think your EntityFramework version was confused

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

See this discussion for getting started: https://stackoverflow.com/questions/5741109/the-type-or-namespace-name-dbcontext-could-not-be-found

And look this same problem and Answer : is Here

Solution 2 - .Net

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

Solution 3 - .Net

I suggest you to check:

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

Solution 4 - .Net

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.

Solution 5 - .Net

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.

Solution 6 - .Net

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

Solution 7 - .Net

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

Solution 8 - .Net

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.

Solution 9 - .Net

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.

Solution 10 - .Net

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>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTania MarinovaView Question on Stackoverflow
Solution 1 - .NetRamesh RajendranView Answer on Stackoverflow
Solution 2 - .NetMazhar KhanView Answer on Stackoverflow
Solution 3 - .NetThilina HView Answer on Stackoverflow
Solution 4 - .NetHarryView Answer on Stackoverflow
Solution 5 - .Netuser1336745View Answer on Stackoverflow
Solution 6 - .NetManoj KargetiView Answer on Stackoverflow
Solution 7 - .NetBrunoView Answer on Stackoverflow
Solution 8 - .NetGraham LaightView Answer on Stackoverflow
Solution 9 - .NetMarc JohnstonView Answer on Stackoverflow
Solution 10 - .NetKumod SinghView Answer on Stackoverflow