Possible null dereference (CS8602)
Key dotnet.codequality.possible-null-dereference · Severity warning · Category codequality
C# compiler nullable analysis CS8602. Flags a member access on a value that may be null at that point - the result of FirstOrDefault, Find, an as-cast or a value the code itself compared with null. The analysis runs even when the project has not switched nullable reference types on. A NullReferenceException at run time is the failure.
Incorrect
Section titled “Incorrect”var user = await _users.FirstOrDefaultAsync(u => u.Email == email);return user.Name;Correct
Section titled “Correct”var user = await _users.FirstOrDefaultAsync(u => u.Email == email);if (user is null) return NotFound();return user.Name;