Skip to content

Maintenance: Enable nullable references across the solution #284

Description

@hjgraca

Summary

C# 8.0 introduced a significant new feature to the language that extends the type system to make a distinction between references that may be null and ones that must not be.
Enabling non-nullability is a radical change, which is why the feature is switched off until we enabled it explicitly

Why is this needed?

Nullability becomes an opt-in feature: a reference will never contain null unless it is explicitly defined as a nullable reference.
Enabling the type system to distinguish between nullable and non-nullable references is going to be a tricky thing to retrofit. C# cannot always guarantee that a non-nullable reference will never contain a null.
However, it can make the guarantee if certain constraints hold, and more generally it will significantly reduce the chances of encountering a NullReferenceException even in cases where it cannot absolutely rule this out.

Which area does this relate to?

Governance

Solution

On each projects .csproj file add inside PropertyGroup the new tag <Nullable>enable</Nullable>

Example:

<PropertyGroup>
  <Nullable>enable</Nullable>
</PropertyGroup>

Acknowledgment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    internalMaintenance changes

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions