2012-04-20 46 views
5

我最近通過在MVC4中創建新的Web應用程序並將所有文件複製過來,最後合併web.config中。所有這些都適用於現有的Web應用程序,但是我今天剛剛注意到一個非常奇怪的錯誤 - 如果我嘗試使用默認的虛擬實現創建一個新的API控制器,然後瀏覽到該API(例如/ api/events),我收到一個Could not load type錯誤。奇怪的是,如果我重建應用程序,並再次命中URL,它似乎是一個不同的組件,它的抱怨,主要是它交替這兩個之間:手動將MVC Web應用程序從3升級到4,無法添加API控制器

Could not load type 'System.Web.Razor.Parser.SyntaxTree.CodeSpan' from assembly 'System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. 

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中包含以下組件綁定信息:

<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看起來像它擁有所有的權利位是:

<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應用程序,它仍然給了我同樣的錯誤(無法加載文件或程序集Microsoft.Scripting)

試圖複製了我的web.config以「香草」一個
+0

你有一個名爲Microsoft.Scripting組件,不是嗎?你是否在命名空間System.Web.Razor.Parser.SyntaxTree中有一個CodeSpan類? – 2012-04-20 16:20:47

回答

7

嘗試刪除從你的web.config這些行

<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> 
相關問題