After enabling ‘Nullable reference types’ in a C# project, I got a lot of the following warnings:
CS8618 - Non-nullable property '<propertyname>' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
I got this message a lot on my ViewModels that looked like this:
I could follow the suggestion and mark the property as nullable as suggested by the compiler. But I know that the ViewModel is populated from the database and that the provided value could never be ‘null’.
In that case the trick to get rid of the warning is to use a property assignment with a default literal: