简体   繁体   中英

Could not load file or assembly 'EntityFramework, Version=6.0.0.0,

I am working with EF . I am trying to execute this line

public ActionResult Edit(string id)
{           
     return View(obj.FindSemesterById(id));
}

I installed EF Version 5 on my project.

But i get this error :

Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

My web.config file :

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="EducationDBEntities" connectionString="metadata=res://*/EducationModel.csdl|res://*/EducationModel.ssdl|res://*/EducationModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=EducationDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>

    </assemblyBinding>

  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

First check which version of EF you using.

You can update the EF version from NuGet Manage Pack.

Go to your Project solution - > 'Manage NuGet packet for Solution', click 'Manage' on 'Entity Framework'.

and also Check your app.config . Maybe the wrong version number is being referenced here.

Edit:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

It's referencing EF Version 5.0.0.0

From the comments section it appears that you weren't able to install the latest version of EF from the public NuGet source because your computer didn't have direct access to the internet and was unable to resolve the www.nuget.org domain. Normally if you configure a proxy in your internet settings, Visual Studio will use this proxy when installing a NuGet from the public repository.

So once you have installed the latest EF 6.1.0 package in your project, the error will go away. Currently you seem to be using some older version of the package and you have projects in your solution that require v6.

Open

Toos > Nuget Package Manager > Package Manager Console

then run

PM> install-package entityframework -version 6.0.0.0

Or You can update it to latest version using below command

PM> Update-Package entityframework 

I faced the same problem today. I had 3 projects in a solution two of which had EF 6.0.0.0 and one of them had 5.0.0.0 . I upgraded the version of that one project when I found this issue. The error went away.

Note: I simply went to References folder of each project and saw the properties of EntityFramework to find out the version of Entity.

Use Nuget to uninstall EF then add it again, Clean and rebuild your project, that worked like a charm. The "uninstall" part in my case was critical, I did a lot of reinstallations and updates and nothing.

I've faced similar problem and same error as you mentioned.

I solved it differently. I noticed that EntityFramework.dll was added to packages folder under Solution Explorer. So I copied EntityFramework.dll from that folder to the bin folder under Solution Explorer and it worked. I know this is not your answer, it may be helpful to other so I just added it.

I had the same problem, and looking through the answers here gave me a hint. My solution has four projects in it. This is a different computer than the one I first created by solution on, so I opened Tools, then NuGet package manager, clicked "Manage NuGet Packages for Solution, found Entity Framework and clicked it once. Then clicked on the Manage button that appeared.

NuGet offered to install EF to one of my projects in the Solution, so I did that. That's when I started getting this error.

Going back to NuGet and checking the boxes to install EF into All of the four projects in the Solution fixed the problem.

Happy again!

如果您的项目名称与您引用的 nuget 包冲突,就会发生这种情况。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM