Zum Inhalt springen

Possible null dereference (CS8602)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.

var user = await _users.FirstOrDefaultAsync(u => u.Email == email);
return user.Name;
var user = await _users.FirstOrDefaultAsync(u => u.Email == email);
if (user is null)
return NotFound();
return user.Name;