Reputation: 951
Consider this example
var task =Task.Factory.StartNew(()=>Console.WriteLine("test"));
task.ContinueWith(antecendent =>
{
ExceptionProcessor.HandleError(task.Exception.Flatten());
}, TaskContinuationOptions.OnlyOnFaulted);
In this example resharper predicts that there is a possible null pointer exception in task.Exception.Flatten() as it assumes task.Exception could be null .
But for all realistic scenarios it is not going to be null as the parameter TaskContinuationOptions.OnlyOnFaulted ensures the method gets called only when an exception occurs.
So How do I tell Resharper to ignore all similar warnings ?
Upvotes: 3
Views: 1159
Reputation: 951
Resharper support team has accepted this as a bug and it can be tracked here http://youtrack.jetbrains.com/issue/RSRP-316492
Upvotes: 3
Reputation: 244968
I think you have several options:
null
check.I don't like #4, you would be making your code less readable just so that ReSharper is happy. I also don't like #3, that could pollute your code with those comments a lot. #2 is better, but I think #1 is the best option: “Posible NullReferenceException” will always have false positives and so you should use it as a guidance: “be careful here, something may be wrong”, not as a strict “you have to fix this”.
Upvotes: 3