Skip to content

Add guidance for configuring nullable context to fix CS8632, CS8636, CS8637 #47306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 15, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,32 @@ The following warnings indicate that you haven't set the nullable context correc
- **CS8636** - *Invalid option for `/nullable`; must be `disable`, `enable`, `warnings` or `annotations`*
- **CS8637** - *Expected `enable`, `disable`, or `restore`*

To set the nullable context correctly, you have two options:

1. **Project-level configuration**: Add the [`<Nullable>`](../compiler-options/language.md#nullable) element to your project file:

```xml
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
```

2. **File-level configuration**: Use [`#nullable`](../preprocessor-directives.md#nullable-context) preprocessor directives in your source code:

```csharp
#nullable enable
```

The nullable context has two independent flags that control different aspects:

- **Annotation flag**: Controls whether you can use `?` to declare nullable reference types and `!` to surpress individual warnings.
- **Warning flag**: Controls whether the compiler emits nullability warnings

For detailed information about nullable contexts and migration strategies, see:

- [Nullable reference types overview](../../nullable-references.md#nullable-context)
- [Update a codebase with nullable reference types](../../nullable-migration-strategies.md)

## Incorrect annotation syntax

These errors and warnings indicate that usage of the `!` or `?` annotation is incorrect.
Expand Down