From f59007c2245e012335d589a2270c119e2d09ff2c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 18:30:40 +0000 Subject: [PATCH 1/3] Initial plan From 94e20e26ab7db9ae377c1e3e65c07ed912e3fd0e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 18:38:32 +0000 Subject: [PATCH 2/3] Add documentation for CS0012 errors in ASP.NET Framework Razor view precompilation Documents the issue from maintenance-packages#257 where upgrading NuGet packages can cause CS0012 errors when precompiling Razor views with aspnet_compiler.exe. - Add new section to redirect-assembly-versions.md explaining the root cause (facade assemblies on .NET Framework 4.7+ not copied to bin folder) and fix (add assemblies to in web.config) - Update oob-packages.md to cross-reference the new documentation Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com> --- .../core-libraries/9.0/oob-packages.md | 4 ++- .../redirect-assembly-versions.md | 33 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/core/compatibility/core-libraries/9.0/oob-packages.md b/docs/core/compatibility/core-libraries/9.0/oob-packages.md index 583c743b4fa49..af869292ed984 100644 --- a/docs/core/compatibility/core-libraries/9.0/oob-packages.md +++ b/docs/core/compatibility/core-libraries/9.0/oob-packages.md @@ -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 --- @@ -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. diff --git a/docs/framework/configure-apps/redirect-assembly-versions.md b/docs/framework/configure-apps/redirect-assembly-versions.md index d06049eeebd63..b79753e111f94 100644 --- a/docs/framework/configure-apps/redirect-assembly-versions.md +++ b/docs/framework/configure-apps/redirect-assembly-versions.md @@ -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" @@ -191,6 +191,35 @@ For example, to redirect one reference to a .NET Framework 3.5 assembly and anot ``` +## Fix CS0012 errors from Razor view precompilation in ASP.NET 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 `` 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 `` `` `` section of your *web.config* file: + +```xml + + + + + + + +``` + +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) From 8d00d48ff4f1b7565b6ebaefd8c3f4179f13f967 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Mar 2026 22:01:10 +0000 Subject: [PATCH 3/3] Move CS0012 Razor precompilation docs to assembly-references.md Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com> --- .../core-libraries/9.0/oob-packages.md | 2 +- .../compiler-messages/assembly-references.md | 26 ++++++++++++++- .../redirect-assembly-versions.md | 33 ++----------------- 3 files changed, 28 insertions(+), 33 deletions(-) diff --git a/docs/core/compatibility/core-libraries/9.0/oob-packages.md b/docs/core/compatibility/core-libraries/9.0/oob-packages.md index af869292ed984..4bc0d9ab7fe37 100644 --- a/docs/core/compatibility/core-libraries/9.0/oob-packages.md +++ b/docs/core/compatibility/core-libraries/9.0/oob-packages.md @@ -55,7 +55,7 @@ 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). +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 [CS0012 in ASP.NET Framework web apps with Razor precompilation](../../../../csharp/language-reference/compiler-messages/assembly-references.md#cs0012-in-aspnet-framework-web-apps-with-razor-precompilation). ## Affected APIs diff --git a/docs/csharp/language-reference/compiler-messages/assembly-references.md b/docs/csharp/language-reference/compiler-messages/assembly-references.md index 65217f6cfa0e7..8281a036a68fc 100644 --- a/docs/csharp/language-reference/compiler-messages/assembly-references.md +++ b/docs/csharp/language-reference/compiler-messages/assembly-references.md @@ -41,7 +41,8 @@ helpviewer_keywords: - "CS8090" - "CS8203" - "CS9286" -ms.date: 05/27/2025 +ms.date: 03/03/2026 +ai-usage: ai-assisted --- # Resolve errors and warnings related to assembly references @@ -118,6 +119,29 @@ If the assembly appears to be referenced in your project but you still receive C dotnet add package [PackageName] ``` +### CS0012 in ASP.NET Framework web apps with Razor precompilation + +In ASP.NET Framework web applications that use `aspnet_compiler.exe` to precompile Razor (*.cshtml*) views, you might see CS0012 errors after you upgrade a NuGet package—even though your regular build succeeds. + +This error occurs when a NuGet package you're using (directly or transitively) depends on an assembly that's 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 `` 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 `` section of your *web.config* file. The assembly name, version, and public key token come from the CS0012 error message: + +```xml + + + + + + + +``` + ## Type forwarding - **CS1068**: *The type name could not be found in the global namespace. This type has been forwarded to another assembly. Consider adding a reference to that assembly.* diff --git a/docs/framework/configure-apps/redirect-assembly-versions.md b/docs/framework/configure-apps/redirect-assembly-versions.md index b79753e111f94..d06049eeebd63 100644 --- a/docs/framework/configure-apps/redirect-assembly-versions.md +++ b/docs/framework/configure-apps/redirect-assembly-versions.md @@ -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, and fix CS0012 errors from Razor view precompilation. -ms.date: "03/03/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. +ms.date: "03/02/2026" ai-usage: ai-assisted helpviewer_keywords: - "assembly binding, redirection" @@ -191,35 +191,6 @@ For example, to redirect one reference to a .NET Framework 3.5 assembly and anot ``` -## Fix CS0012 errors from Razor view precompilation in ASP.NET 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 `` 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 `` `` `` section of your *web.config* file: - -```xml - - - - - - - -``` - -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)