Skip to content

Commit 3af99cf

Browse files
shethaaditAdit ShethBillWagner
authored
Add guidance for configuring nullable context to fix CS8632, CS8636, CS8637 (#47306)
* Fixed bu 47305. * Update docs/csharp/language-reference/compiler-messages/nullable-warnings.md Co-authored-by: Bill Wagner <[email protected]> * Update docs/csharp/language-reference/compiler-messages/nullable-warnings.md * Update docs/csharp/language-reference/compiler-messages/nullable-warnings.md * Update docs/csharp/language-reference/compiler-messages/nullable-warnings.md * Update docs/csharp/language-reference/compiler-messages/nullable-warnings.md * Removed blank space. --------- Co-authored-by: Adit Sheth <[email protected]> Co-authored-by: Bill Wagner <[email protected]>
1 parent f218d18 commit 3af99cf

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/csharp/language-reference/compiler-messages/nullable-warnings.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,32 @@ The following warnings indicate that you haven't set the nullable context correc
215215
- **CS8636** - *Invalid option for `/nullable`; must be `disable`, `enable`, `warnings` or `annotations`*
216216
- **CS8637** - *Expected `enable`, `disable`, or `restore`*
217217

218+
To set the nullable context correctly, you have two options:
219+
220+
1. **Project-level configuration**: Add the [`<Nullable>`](../compiler-options/language.md#nullable) element to your project file:
221+
222+
```xml
223+
<PropertyGroup>
224+
<Nullable>enable</Nullable>
225+
</PropertyGroup>
226+
```
227+
228+
2. **File-level configuration**: Use [`#nullable`](../preprocessor-directives.md#nullable-context) preprocessor directives in your source code:
229+
230+
```csharp
231+
#nullable enable
232+
```
233+
234+
The nullable context has two independent flags that control different aspects:
235+
236+
- **Annotation flag**: Controls whether you can use `?` to declare nullable reference types and `!` to surpress individual warnings.
237+
- **Warning flag**: Controls whether the compiler emits nullability warnings
238+
239+
For detailed information about nullable contexts and migration strategies, see:
240+
241+
- [Nullable reference types overview](../../nullable-references.md#nullable-context)
242+
- [Update a codebase with nullable reference types](../../nullable-migration-strategies.md)
243+
218244
## Incorrect annotation syntax
219245

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

0 commit comments

Comments
 (0)