Skip to content
Merged
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
35 changes: 26 additions & 9 deletions docs/csharp/language-reference/compiler-messages/cs0518.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Project Sdk="Microsoft.NET.Sdk">`) or legacy project formats. SDK-style projects manage runtime references automatically through the `<TargetFramework>` 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 `<TargetFramework>` 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)]

Expand All @@ -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 `<TargetFramework>` property specifies the intended runtime:

```xml
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
```

For multi-targeting projects, use `<TargetFrameworks>` (plural):

```xml
<PropertyGroup>
<TargetFrameworks>net8.0;net48</TargetFrameworks>
</PropertyGroup>
```

- 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.
Loading