You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Diagnostic ID: [CS8618] Non-nullable property 'XXX' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Describe the bug
The analyzer identifies a member property Message as being not-set in the following constructor:
public class Test
{
private string Message { get; set; }
public Test()
{
Message = "";
Console.WriteLine($"Message size: {Message?.Length}");
}
}
Steps To Reproduce
Compile the above class.
Expected behavior
No warnings.
Actual behavior
The compiler (and VS2022 editor) complains with:
warning CS8618: Non-nullable property 'Message' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Additional context
If Message?.Length is changed to Message!.Length then no warning is issued. But I would not expect the ?. operator to change the compiler warning - from my point of view, the property Message should have the same nullability whether ?. or !. is used - the code does assign Message a value in the constructor.
The text was updated successfully, but these errors were encountered:
Analyzer
Diagnostic ID: [CS8618] Non-nullable property 'XXX' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Analyzer source
.NET SDK:
Version: 8.0.304
Commit: 352dc5a01f
Workload version: 8.0.300-manifests.113cb230
MSBuild version: 17.10.4+10fbfbf2e
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.304\
.NET workloads installed:
[aspire]
Installation Source: VS 17.10.35201.131
Manifest Version: 8.1.0/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.8
Architecture: x64
Commit: 08338fcaa5
.NET SDKs installed:
8.0.304 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Describe the bug
The analyzer identifies a member property
Message
as being not-set in the following constructor:Steps To Reproduce
Compile the above class.
Expected behavior
No warnings.
Actual behavior
The compiler (and VS2022 editor) complains with:
warning CS8618: Non-nullable property 'Message' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
Additional context
If
Message?.Length
is changed toMessage!.Length
then no warning is issued. But I would not expect the?.
operator to change the compiler warning - from my point of view, the propertyMessage
should have the same nullability whether?.
or!.
is used - the code does assignMessage
a value in the constructor.The text was updated successfully, but these errors were encountered: