2012-06-05 40 views
40

自從使用Visual Studio 2012 RC後,我們在剃鬚刀視圖中使用便攜式類庫(.net 4.5 & metro配置文件)中的類時遇到了HttpCompileException。使用Visual Studio 2012 RC的MVC 4/Razor中的可移植類庫?

例外:(德語到英語翻譯對谷歌,對不起)

System.Web.HttpCompileException (0x80004005):  
c:\Users\user\AppData\Local\Temp\Temporary ASP.NET   
Files\root\1995167a\126b7c4d\App_Web_index.cshtml.1fbcdbb1.zaniprm5.0.cs(29): 

error CS0012: The type 'System.Object' is not in a referenced assembly is 
defined. Add a reference to the Assembly "System.Runtime, Version = 4.0.0.0, 
Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" added. 

at 
System.Web.Compilation.AssemblyBuilder.Compile() 
System.Web.Compilation.BuildProvidersCompiler.PerformBuild()  
System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) 
... 

解決方案結構:

  • 移植類庫(.NET 4.5 &地鐵輪廓)
    • 公共類用戶{...}
  • MVC 4(.NET 4.5)
    • 參考移植類庫
    • 剃刀視圖
      • @model用戶

由於的Visual Studio 2012 RC添加參考「系統。運行時間「是不可能的。

+1

作爲一種解決方法,除了.NET 4.5和Metro風格之外,是否還可以將可移植類庫更改爲定位Silverlight 5? –

回答

60

在視圖\ Web.config文件,添加下<system.web>部分添加以下代碼:

<compilation debug="true" targetFramework="4.5"> 
    <assemblies> 
     <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </assemblies> 
</compilation> 

還有一堆的其他組件可能還需要參考,具體取決於什麼類型的便攜式代碼正在使用。您可以在遇到錯誤時添加每個組件,或者在C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades中添加組件的完整列表。

+16

這爲什麼有效? –

+2

這爲我解決了一個類似的問題,使用System.Collections.Immutable – aboy021

+0

根據你在你的項目中做什麼,你可能還需要添加同樣的行到根'Web.Config' – joshcomley

相關問題