简体   繁体   English

将应用程序从.NET 4.5重新指向4.0后的参考错误

[英]Reference error after repointing application from .NET 4.5 to 4.0

I build an application pointing to .NET 4.5 but need to run it on a server that only has .NET 4.0, so I retargeted the application and uninstalled/reinstalled several references as prompted: 我构建了一个指向.NET 4.5的应用程序,但需要在仅具有.NET 4.0的服务器上运行它,因此我重新定位了该应用程序的位置,并根据提示卸载/重新安装了多个引用:

  • Antlr 蚂蚁
  • EntityFramework 实体框架
  • Newtonsoft.Json 牛顿
  • Microsoft.AspNet.Mvc Microsoft.AspNet.Mvc
  • Microsoft.AspNet.Web.Optimization Microsoft.AspNet.Web.Optimization
  • Microsoft.AspNet.WebPages Microsoft.AspNet.WebPages
  • Microsoft.Web.Infrastructure Microsoft.Web.Infrastructure
  • WebGrease Web油脂

I now have no build errors in Visual Studio, but when running the project I get the following error: 我现在在Visual Studio中没有构建错误,但是在运行项目时出现以下错误:

Could not load file or assembly 'System.Web.Mvc, Version=5.1.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its
dependencies. The located assembly's manifest definition does not
match the assembly reference. (Exception from HRESULT: 0x80131040)

Which makes sense because I had to install version 4.0, but how do I remove this error? 这是有道理的,因为我必须安装4.0版,但是如何删除此错误?

It does not appear that I am referencing any .NET 4.5 dependencies in packages.config : 看来我没有在packages.config引用任何.NET 4.5依赖项:

<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net40" />
  <package id="AspNetMvc" version="4.0.20710.0" targetFramework="net40" />
  <package id="bootstrap" version="3.1.1" targetFramework="net40" />
  <package id="EntityFramework" version="6.1.0" targetFramework="net40" />
  <package id="jQuery" version="1.9.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net40" />
  <package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="6.0.3" targetFramework="net40" />
  <package id="PagedList" version="1.17.0.0" targetFramework="net40" />
  <package id="PagedList.Mvc" version="4.5.0.0" targetFramework="net40" />
  <package id="WebGrease" version="1.5.2" targetFramework="net40" />
</packages>

It looks like the offending reference is in ~/Views/Web.config: 看起来令人讨厌的引用位于〜/ Views / Web.config中:

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
  <!-- Namespaces removed -->
</system.web.webPages.razor>

You need to install 4.5 on the server or rebuild all projects and dependencies for 4.0. 您需要在服务器上安装4.5或重建4.0的所有项目和依赖项。 If you are using a 4.5 dependency, you need to remove it and add a 4.0 counterpart instead. 如果使用的是4.5依赖项,则需要将其删除并添加4.0依赖项。

It looks like you may have installed the incorrect version of the MVC Framework. 看来您安装的MVC Framework版本不正确。 Check which version you have referenced in your project and ensure you have that version available on the server. 检查项目中引用的版本,并确保服务器上具有该版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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