JetBrains Rider 2017.2 Help

Code Inspection: Member with '[NotNull]' attribute is not initialized at constructor exit

This code inspection warns you that the contract for a field or a property marked with the [NotNullAttribute] may no work because this member can still be null when the object is created.

In the example below, JetBrains Rider warns you that PlaceOfBirth is not initialized:

class Person { [NotNull] public string Name { get; set; } [NotNull] public string PlaceOfBirth { get; set; } // Warning: Member with '[NotNull]' attribute is not initialized public Person([NotNull] string name, string placeOfBirth) { Name = name; Console.WriteLine(@"Name: {0}, Place of birth: {1}", name, placeOfBirth); } }

Note that the inspection only checks usages of the member inside constructor code. So if you initialize the member in some other method that is called in constructor, JetBrains Rider will still warn you about the not initialized member. In this case, suppress this inspection with the following comment: // ReSharper disable once NotNullMemberIsNotInitialized

Last modified: 17 November 2017

See Also