Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "New version of some OOB packages"
description: Learn about the breaking change in core .NET libraries where updates were made to TFMs and package versions for several OOB packages.
ms.date: 12/4/2024
ms.date: 03/03/2026
ai-usage: ai-assisted
ms.custom: https://github.com/dotnet/docs/issues/43564
---
Expand Down Expand Up @@ -55,6 +55,8 @@ The source code of these packages was moved from their old branch, which was alr

Depending on the package, different recommended actions are provided. For more information, see the [package support policy](https://github.com/dotnet/maintenance-packages/tree/main/package-support-policy.md).

If you're using these packages in an ASP.NET Framework web application that precompiles Razor (*.cshtml*) views with `aspnet_compiler.exe`, upgrading to new package versions might cause `CS0012` errors because some assemblies are framework facades that aren't copied to the bin folder. For more information and the fix, see [Fix CS0012 errors from Razor view precompilation in ASP.NET web apps](../../../../framework/configure-apps/redirect-assembly-versions.md#fix-cs0012-errors-from-razor-view-precompilation-in-aspnet-web-apps).

## Affected APIs

All APIs contained in the affected packages.
33 changes: 31 additions & 2 deletions docs/framework/configure-apps/redirect-assembly-versions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Redirecting Assembly Versions"
description: Redirect compile-time binding references to different versions of .NET assemblies, third-party assemblies, or your own app's assemblies. Learn how to enable binding redirects for unit test projects.
ms.date: "03/02/2026"
description: Redirect compile-time binding references to different versions of .NET assemblies, third-party assemblies, or your own app's assemblies. Learn how to enable binding redirects for unit test projects, and fix CS0012 errors from Razor view precompilation.
ms.date: "03/03/2026"
ai-usage: ai-assisted
helpviewer_keywords:
- "assembly binding, redirection"
Expand Down Expand Up @@ -191,6 +191,35 @@ For example, to redirect one reference to a .NET Framework 3.5 assembly and anot
</assemblyBinding>
```

## Fix CS0012 errors from Razor view precompilation in ASP.NET web apps
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the best place to put this. It's not necessarily a characteristic of assembly redirection / conflicts. I can reproduce this error simply by adding a reference to something not in the default set and using that in CSHTML. @copilot do we have any docs that discuss adding references and these web apps?


In ASP.NET Framework web applications that use `aspnet_compiler.exe` to precompile Razor (*.cshtml*) views, you might see errors like the following after you upgrade a NuGet package:

```
error CS0012: The type 'X' is defined in an assembly that is not referenced. You must add a reference to assembly 'AssemblyName, Version=..., Culture=neutral, PublicKeyToken=...'.
```

This error occurs when a NuGet package you're using (directly or transitively) depends on an assembly that is a *facade* on your target framework version—for example, `System.ValueTuple`, `System.Runtime`, `netstandard`, or `System.Net.Http` on .NET Framework 4.7 and later. Because these assemblies are part of the framework itself, NuGet doesn't copy their DLLs into your application's bin folder.

The MSBuild compiler resolves these references correctly during a normal build. However, `aspnet_compiler.exe` uses a separate mechanism: it reads assembly references from the bin folder and from the `<compilation><assemblies>` section of your *web.config* file. When the assembly isn't in either location, the Razor compiler can't find it and reports a CS0012 error.

> [!NOTE]
> This error only affects *.cshtml* (Razor) files. Files like *.aspx* and *.ascx* compile with a different code path and don't have this limitation.

To fix the error, add the missing assembly to the `<system.web>` `<compilation>` `<assemblies>` section of your *web.config* file:

```xml
<system.web>
<compilation>
<assemblies>
<add assembly="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
</assemblies>
</compilation>
</system.web>
```

Replace the assembly name, version, and public key token with those of the assembly in the CS0012 error message.

## See also

- [How to: Enable and Disable Automatic Binding Redirection](how-to-enable-and-disable-automatic-binding-redirection.md)
Expand Down
Loading