Keywords: ASP.NET MVC | System.Runtime | Portable Class Library | Build Error | Facade Assembly
Abstract: This technical paper provides an in-depth examination of System.Runtime reference errors encountered when integrating Portable Class Libraries into ASP.NET MVC 5.1 projects. Through detailed analysis of error root causes, Facade assembly mechanisms, and comprehensive configuration solutions, developers can effectively resolve compilation failures on build servers. The article presents practical case studies and step-by-step implementation guidelines.
Problem Context and Error Analysis
During ASP.NET MVC 5.1 project development, when integrating third-party Portable Class Libraries, build servers frequently report the following compilation error:
The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0
This error originates from compatibility issues between Portable Class Libraries and the full .NET Framework. PCLs are designed for cross-platform deployment, and their type referencing mechanism differs from traditional .NET applications.
Facade Assembly Mechanism Explained
In .NET Framework 4.5 and later versions, Microsoft introduced the concept of Facade assemblies. These assemblies reside in specific paths:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Runtime.dll
Facade assemblies act as type forwarders, redirecting type references from Portable Class Libraries to the full .NET Framework implementation. When build servers lack these assemblies, type resolution fails.
Solution Implementation
To resolve this issue, proper compilation settings must be configured in the web.config file. First, expand the default compilation section:
<compilation debug="true" targetFramework="4.5"/>
Then add the assemblies subsection, explicitly referencing the System.Runtime assembly:
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</assemblies>
</compilation>
Build Server Configuration Considerations
In local development environments, Visual Studio typically handles Facade assembly references automatically. However, on build servers, ensure:
- Build servers have the corresponding .NET Framework development tools installed
- Reference assembly paths are correctly configured
- All necessary Facade assemblies are available
Technical Principles Deep Dive
Portable Class Libraries achieve cross-platform compatibility through type forwarding. When PCLs reference fundamental types, these references are redirected to platform-specific implementations. In the full .NET Framework, the System.Runtime assembly contains metadata for these type forwards, ensuring correct type resolution.
Best Practices Recommendations
To avoid similar issues, recommend:
- Test build server integration early in the project lifecycle
- Ensure all development and build environments use the same .NET Framework version
- Regularly update NuGet packages to obtain the latest compatibility fixes
- Include PCL compatibility testing in continuous integration workflows