Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
330 views
in Technique[技术] by (71.8m points)

c# - Portable Class Library in MVC 4 / Razor with Visual Studio 2012 RC?

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:UsersuserAppDataLocalTempTemporary ASP.NET        
Files
oot1995167a126b7c4dApp_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.

question from:https://stackoverflow.com/questions/10897712/portable-class-library-in-mvc-4-razor-with-visual-studio-2012-rc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the ViewsWeb.config file, add the following code under the <system.web> section:

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

There are a bunch of other assemblies you may also need to reference, depending on what types your portable code is using. You can either add each one as you encounter the error, or add the full list of assemblies in C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETFrameworkv4.5Facades.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...