c# - 无法加载文件或程序集 'EntityFramework,版本 = 6.0.0.0,

标签 c# asp.net asp.net-mvc entity-framework nuget

我正在使用 EF。 我正在尝试执行这一行

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

我在我的项目中安装了 EF 版本 5。

但是我得到这个错误:

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)

我的 web.config 文件:

<?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>

最佳答案

从评论部分看来,您无法从公共(public) NuGet 源安装最新版本的 EF,因为您的计算机无法直接访问 Internet,并且无法解析 www. nuget.org 域。通常,如果您在 Internet 设置中配置代理,Visual Studio 将在从公共(public)存储库安装 NuGet 时使用此代理。

所以一旦你安装了最新的EF 6.1.0包在你的项目中,错误就会消失。目前您似乎正在使用该软件包的一些旧版本,并且您的解决方案中有需要 v6 的项目。

关于c# - 无法加载文件或程序集 'EntityFramework,版本 = 6.0.0.0,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22579545/

相关文章:

c# - 在 Azure 中使用 GraphServiceClient 和客户端 key 时出现授权异常

css - asp.net mvc 如何让表头居中对齐?

asp.net-mvc - 单例和 ASP.NET MVC

asp.net-mvc - 对 POST 的 MVC 路由进行单元测试

c# - 如何只绘制屏幕上可见的图 block ( Sprite )

c# - 为什么以相反的顺序调用构造函数?

asp.net - Paypal 在交易后从不重定向到我的网站

asp.net - 如何摆脱Ajax HTML编辑器中的复制和粘贴文本样式

C#读写给定缓冲区长度的文件并剪切溢出

asp.net - 我们可以在同一个应用程序中将 session 状态和缓存存储在 Redis 缓存上吗?