CSHTML Razor Pages Model is null - False Positive?

We recently have issues in CSHTML Razor pages in ASP.NET Core (.NET Core 9) when it comes to the views, where we get a Dereference of a possibly null reference.message for accessing properties of a model, eventhough there es an explicit check if the Model is not null.

Mini-Sample

@model MyModel

@if (Model is not null)
{
    <partial name="_MyPartial.cshtml" model="@Model.MySubProperty" />
}

Actual issue found by SonarQube

Version: SonarQube Server Enterprise v2025.3 (on prem / zip)

Hey there.

This looks like a compiler warning, CS8602 being imported to SonarQube, rather than an issue being raised by SonarQube itself.

It doesn’t seem like you’re the first. These pages might help.