Here’s my code that declares & sets ReturnUrl
.
public class ExPageBase : ExComponentBase
{
[Parameter]
[SupplyParameterFromQuery(Name = "returnUrl")]
public string? ReturnUrl { get; set; }
[MemberNotNull (nameof(ReturnUrl))]
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
if (string.IsNullOrEmpty(ReturnUrl))
{
if (Principal.IsSysAdmin())
ReturnUrl = GlobalConstants.UrlSysAdminHomePage;
else if (Principal.IsManager())
ReturnUrl = GlobalConstants.UrlManagerHomePage;
else if (Principal.IsOnlyVolunteer())
ReturnUrl = GlobalConstants.UrlVolunteerHomePage;
else
ReturnUrl = GlobalConstants.UrlHomePage;
}
}
}
I am getting the following warning when I compile:
5>C:GitLouisHoweLouisHowe.webSharedExPageBase.cs(51,4,51,35): warning CS8774: Member 'ReturnUrl' must have a non-null value when exiting.
Line 51 is: await base.OnInitializedAsync();
Why does it say that ReturnUrl
must have a non-null value anywhere for any reason?
And why in particular when exiting a call to the base OnInitializedAsync()
when I am still inside my OnInitializedAsync()
?
I can understand it giving me a warning due to the MemberNotNull
when exiting from my OnInitializedAsync()
. But why from calling the base one?
This code is for Blazor Interactive Server although I think that is irrelevant to this question.