[AllowNull] attribute ignored by Resharper

Resharper version = 2020.2.1

Consider the following code from a .Net Core 3.1 console application:

using System;
using System.Diagnostics.CodeAnalysis;

#nullable enable

namespace ConsoleApp1
{

    class Program
{
static void Main()
{
Test test = new Test
{
SomeProperty = null // R# warning: Possible null assignment.
};

Console.WriteLine(test.SomeProperty);
}
}

public sealed class Test
{
[AllowNull]
public string SomeProperty
{
get => _someProperty;

set
{
_someProperty =
value != null // R# warning: Expression is always true.
? value
: "default";
}
}

string _someProperty = "";
}
}

The [AllowNull] attribute tells the compiler that although the SomeProperty getter cannot return null,
the setter can accept null.

The C# compiler is happy with this, and does not issue any warnings or errors.

However, Resharper gives two incorrect warnings, as commented in the code above
("// R# warning: ...").

Is this a problem with Resharper, or have I configured Resharper incorrectly?
0
2 comments
Official comment

Hello Matthew,

Thanks for the report. It is a bug in the code analysis. However, it has already been fixed in 2020.3 branch, and the fix will be available in the first EAP build of ReSharper 2020.3 release cycle.

Thanks! 

Great, thanks for the swift response!

0

Please sign in to leave a comment.