ReSharper wrongly warns of InvalidOperationException
Answered
Hi,
I have a weird issue with ReSharper 2019.1.1 in Visual Studio 2019 v 16.0.3. I tried to create a minimal example that resembles my situation.
ReSharper warns me that an InvalidOperationException might occur because Address might be null at new ByteConsumer. When I let ReSharper fix it automatically, it just adds the fist null-check in my if-clause again, which does not really change anything, but seems to satisfy ReSharpers analyzers.
public class InnerClass
{
public byte? Address { get; set; }
public bool HasId()
{
return DateTime.Now.Ticks % 2 > 0.5;
}
}
public class OuterClass
{
public InnerClass Inner { get; set; }
}
public class OwnerClass
{
public OwnerClass(OuterClass outer)
{
if (outer.Inner?.Address != null && outer.Inner.HasId())
{
// this is where resharper says an InvalidOperationException might occur
var consumer = new ByteConsumer(outer.Inner.Address.Value);
}
}
}
Could this be a bug?
Please sign in to leave a comment.
Hello!
Thank you for the feedback.
I've filed corresponding issue here - https://youtrack.jetbrains.com/issue/RSRP-474729.
You are welcome to comment or vote for it.
Thank you.