Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC4 WebAPI EntityFramework exception

I am trying to create a webapi controller, within a site. it is a template controller, nothing changed from what visual studio has inserted.

The code is within an MVC4 site, which runs completely without any errors, however, when I call webapi controller, I am receiving this error:

Could not load file or assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.

I have uninstalled EntityFramework nuget package, and when I search in entire solution, it is not found in any file, however, I am repeatedly receiving this error.

Any clues what might be a possible solution to this?

like image 405
Arian Avatar asked Mar 04 '26 10:03

Arian


2 Answers

I had the same problem.

All things were working and then just started to give a 404 for all web api requests.

I have tried everything .. the only thing that resolved my issue was to add a reference of EF 4.1.0.0 to my project and also to add it to Web.config.

It strange because nowhere in my solution im using or referencing EF.

I didnt have 4.1 version and I downloaded it from here http://www.microsoft.com/en-us/download/details.aspx?id=26825


I found why EF 4.1 is listed as dependency. The error came only when i wanted to publish the site. And what i did is only to Add Deployable Dependecies and check ASP.NET MVC, because the host server didn't have MVC 4 installed. When i looked on _bin_deployableAssemblies folder

enter image description here

my eye caught System.Web.Http.Data.EntityFramework.dll and immediately i decompiled and voila i found EF 4.1 referenced there.

enter image description here

like image 125
s33sharp_94 Avatar answered Mar 07 '26 20:03

s33sharp_94


Arian, I see that error every time I do something with the stock VS template when using EF4.

Turn it around and install Entity Framework again in the solution. Launch the Nuget manager or do it from its console:

Install-Package EntityFramework 

(for 4.3.1)

Install-Package EntityFramework -Pre  

(for 5.0.0rc)

Once you have the DLL in your references (btw, check that), the error goes away

like image 36
AFD Avatar answered Mar 07 '26 19:03

AFD