Tania Marinova
Tania Marinova

Reputation: 1898

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

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

Upvotes: 52

Views: 81200

Answers (10)

Ninja kargeti
Ninja kargeti

Reputation: 161

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

Upvotes: 2

Kumod Singh
Kumod Singh

Reputation: 2163

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>

Upvotes: 0

Marc Johnston
Marc Johnston

Reputation: 1286

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.

Upvotes: 0

Harry
Harry

Reputation: 3195

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.

Upvotes: 5

Graham Laight
Graham Laight

Reputation: 4840

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.

Upvotes: 0

Bruno
Bruno

Reputation: 563

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

Upvotes: 0

user1336745
user1336745

Reputation: 51

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.

Upvotes: 2

Mazhar Khan
Mazhar Khan

Reputation: 404

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

Upvotes: 10

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38663

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

Upvotes: 64

Thilina H
Thilina H

Reputation: 5804

I suggest you to check:

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

Upvotes: 5

Related Questions