From 49ee4aee57426a611765f2f8ebbfeb27d5b2ee83 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 31 Jul 2025 16:06:00 +0000 Subject: [PATCH 1/3] Initial plan From 2fc8820941d361009a42a38c49b62eede3026566 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 31 Jul 2025 16:13:22 +0000 Subject: [PATCH 2/3] Update CS0518 documentation with modern .NET project guidance Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- .../compiler-messages/cs0518.md | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/cs0518.md b/docs/csharp/language-reference/compiler-messages/cs0518.md index 4e39b1afd5a50..54397dc16a9fc 100644 --- a/docs/csharp/language-reference/compiler-messages/cs0518.md +++ b/docs/csharp/language-reference/compiler-messages/cs0518.md @@ -11,8 +11,11 @@ ms.assetid: b0b61cbb-c9a7-48c9-9e60-7cdd5ecb3e6c # Compiler Error CS0518 Predefined type 'type' is not defined or imported - -The main cause for this problem is that the project is not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following: + +> [!NOTE] +> The resolution for this error depends on whether you're using a modern SDK-style project (`.csproj` files that start with ``) or legacy project formats. SDK-style projects manage runtime references automatically through the `` property. + +The main cause for this problem is that the project cannot access the predefined types from the .NET runtime library. In modern SDK-style projects, this is typically due to an incorrect or missing `` specification. In legacy projects, this issue is caused by not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following: [!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)] @@ -25,13 +28,27 @@ The main cause for this problem is that the project is not importing mscorlib.dl - Residual components from an earlier installation that are incompatible with the latest installation remain. To resolve this problem, take one of the following actions: - + - Do not specify the /nostdlib option from the command line compiler. - -- Make sure that the project refers to the correct mscorlib.dll. - -- Reinstall the .NET Framework common language runtime (if the previous solutions do not solve the problem). -Optionally +- For modern SDK-style projects, ensure the project targets the correct .NET runtime. In your `.csproj` file, verify the `` property specifies the intended runtime: + + ```xml + + net8.0 + + ``` + + For multi-targeting projects, use `` (plural): + + ```xml + + net8.0;net48 + + ``` + +- For legacy project formats, make sure that the project refers to the correct mscorlib.dll. + +- Reinstall the .NET Framework common language runtime (if the previous solutions do not solve the problem). -- Reload the project in the Visual Studio. +- Reload the project in Visual Studio. From 0ebce552202fc0befe2b233923100e73cfff9419 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Mon, 4 Aug 2025 10:45:54 -0700 Subject: [PATCH 3/3] Update docs/csharp/language-reference/compiler-messages/cs0518.md --- docs/csharp/language-reference/compiler-messages/cs0518.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/compiler-messages/cs0518.md b/docs/csharp/language-reference/compiler-messages/cs0518.md index 54397dc16a9fc..a0c45f1dd582b 100644 --- a/docs/csharp/language-reference/compiler-messages/cs0518.md +++ b/docs/csharp/language-reference/compiler-messages/cs0518.md @@ -15,7 +15,7 @@ Predefined type 'type' is not defined or imported > [!NOTE] > The resolution for this error depends on whether you're using a modern SDK-style project (`.csproj` files that start with ``) or legacy project formats. SDK-style projects manage runtime references automatically through the `` property. -The main cause for this problem is that the project cannot access the predefined types from the .NET runtime library. In modern SDK-style projects, this is typically due to an incorrect or missing `` specification. In legacy projects, this issue is caused by not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following: +The main cause for this problem is that the project cannot access the predefined types from the .NET runtime library. In modern SDK-style projects, this is typically due to an incorrect or missing `` specification. In legacy projects, this issue is caused by not importing mscorlib.dll, which defines the entire namespace. This can be caused by one of the following: [!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]