3

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?

3
  • did u check global.asax.cs? AFAIK, they stick a config there for EF to use LocalDB in vs11 beta if that's one that u are using. Commented May 27, 2012 at 22:40
  • Maybe there is an entry left from EF in your web.config file? I'd look into connectionStrings section first. Commented May 27, 2012 at 22:41
  • I've tried installing the latest version of EF stable to resolve this in my own Web API + EntityFramework "could not load file or assembly" fun-a-palooza and it did not work either :( Commented May 28, 2012 at 1:55

8 Answers 8

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I had deployable dependencies in my project... Looked like that was part of the culprit. Still ran into problems with the EF dependency though even after I removed them.
I just installed Entity-Framework 4.3.1 from nuget.And then added as dependentAssembly in web config (see @joshjs answer below). From 31 May my beta project is up and didnt show any bugs. Now i'm gooing to see forward to look WEB API RC because i've noticed some big changes.
1

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

1 Comment

Do you use EF in a few projects? If you do, you need to upgrade it to the latest version in all of them
1

Try adding the following to your web.config file:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Comments

0

it is a template controller, nothing changed from what visual studio has inserted.

Entity Framework might be a dependency because of these templates. Some of the templates will generate DataControllers, which require EF. If you read carefully, you will see in the text displayed by the template: "Generate ...., using Entity Framework"

If that is not the case, and you have simple ApiControllers, and you've uninstalled EF, double-check your packages.config file, to make sure that there is no reference to Entity Framework there either.

Comments

0

Try deleting the obj and bin folders for each project then rebuilding the application. This has helped me fix the same problem on more than one occasion.

Comments

0

Try opening the .csproj file for your project in a text editor such as Notepad and searching for the phrase "EntityFramework". If it turns up hits, that may give you a clue as to what that problem is.

Comments

0

Removing the web.config dependentAssembly lines for EntityFramework fixed it for my project.

Screenshot of web.config code - dependentAssembly - EntityFramework

Comments

0

In my case, since I was using .NET 4.0 I had to revert back to EntityFramework 4.1 after my uprade to VS2012 (needed for a different project).

Running in the Package Manager Console in VS 2010 this command:

PM> Install-Package EntityFramework -Version 4.1.10715.0

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.