diff --git a/docs/csharp/language-reference/compiler-messages/cs0518.md b/docs/csharp/language-reference/compiler-messages/cs0518.md index 4e39b1afd5a50..a0c45f1dd582b 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 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.