首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >手动将MVC web应用从%3升级到% 4,无法添加API控制器

手动将MVC web应用从%3升级到% 4,无法添加API控制器
EN

Stack Overflow用户
提问于 2012-04-20 23:26:45
回答 1查看 4.1K关注 0票数 5

我最近在MVC4中创建了一个新的web应用程序,并复制了所有文件,最后合并了web.config,从而将我的web应用程序从MVC3升级到了4。所有这些都在现有的web应用上运行得很好,但是我今天刚刚注意到一个非常奇怪的错误--如果我试图用默认的虚拟实现创建一个新的API控制器,然后浏览到那个api (例如/api/events),我得到一个Could not load type错误。奇怪的是,如果我重新构建应用程序,并再次点击URL,它抱怨的似乎是一个不同的程序集,主要是这两个程序集之间的交替:

代码语言:javascript
复制
Could not load type 'System.Web.Razor.Parser.SyntaxTree.CodeSpan' from assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

代码语言:javascript
复制
Could not load file or assembly 'Microsoft.Scripting, Version=1.1.0.20, Culture=neutral, PublicKeyToken=7f709c5b713576e1' or one of its dependencies. The system cannot find the file specified.

我的web.config包含以下程序集绑定信息:

代码语言:javascript
复制
 <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="0.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>
      <dependentAssembly>
        <!--<assemblyIdentity name="FluentValidation" publicKeyToken="a82054b837897c66" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />-->
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.8.0" newVersion="4.0.8.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

而且我的packages.config看起来包含了所有正确的部分:

代码语言:javascript
复制
  <package id="AspNetMvc" version="4.0.20126.16343" />
  <package id="AspNetRazor.Core" version="2.0.20126.16343" />
  <package id="AspNetWebApi" version="4.0.20126.16343" />
  <package id="AspNetWebApi.Core" version="4.0.20126.16343" />
  <package id="AspNetWebPages.Core" version="2.0.20126.16343" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
  <package id="Microsoft.Web.Optimization" version="1.0.0-beta" />
  <package id="System.Net.Http" version="2.0.20126.16343" />
  <package id="System.Net.Http.Formatting" version="4.0.20126.16343" />
  <package id="System.Web.Http.Common" version="4.0.20126.16343" />
  <package id="System.Web.Providers" version="1.1" />
  <package id="System.Web.Providers.Core" version="1.0" />

我甚至尝试过从一个新的mvc4 web应用程序中用“普通”程序复制我的web.config,仍然给出同样的错误(无法加载文件或程序集Microsoft.Scripting)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-04-23 20:55:22

尝试从web.config中删除这些行

代码语言:javascript
复制
<dependentAssembly>
  <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10249049

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档