40

since working with Visual Studio 2012 RC we get an HttpCompileException when using a class out of an portable class library (.net 4.5 & metro profile) within a razor view.

Exception: (german to english translated on google, sorry)

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)
...

Solution structure:

  • Portable Class Library (.net 4.5 & metro profile)
    • public class User { ... }
  • MVC 4 (.net 4.5)
    • Reference to Portable Class Library
    • Razor-View
      • @model User

Since Visual Studio 2012 RC adding reference "System.Runtime" is not possible any more.

4

1 回答 1

60

在 Views\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.

于 2012-07-09T23:16:39.977 回答