C# – Ignore the Nullable CS8618 warning in DTO classes

When you have the Nullable Reference Types feature (Nullable for short) enabled, one of the warnings you’ll run into is the following: CS8618 Non-nullable property X must contain a non-null value when exiting constructor. This warning doesn’t make sense in a very common scenario: You can just ignore the warning when it applies to DTOs. … Read more

C# – Nullable Reference Types feature basics

The main purpose of the Nullable Reference Types (NRT) feature is to help prevent NullReferenceExceptions by showing you compiler warnings. You can make a reference type nullable (ex: Movie? movie) or non-nullable (ex: Movie movie). This allows you to indicate how you plan on using these references. The compiler uses this info while analyzing actual … Read more

CA1062: Validate parameter is non-null before using it

When you have a public method that isn’t null checking its parameters, then you’ll get the CA1062 code analysis warning. This is part of the Nullable Reference Types feature. For example, the following code isn’t null checking the movieRepository parameter: This results in the CA1062 code analysis warning: CA1062 In externally visible method ‘void StreamingService.LogMovies(MovieRepository … Read more