Search code examples
c#xamarin.iosresharperrider

Why does ReSharper claim "Expression is always true" in inlined function but not in method?


The code had no errors in Rider 2020.2 and before I upgraded Rider to 2020.3.1 and also the ReSharper Command Line tools. Now I get this weird warning in a Xamarin C# project:

var controller = new UIActivityViewController(items.ToArray(), null);
controller.CompletionWithItemsHandler = (activityType, completed, returnedItems, error) =>
{
    // here: Expression is always true
    if (error != null)
    {
        logger.Error("Error: {0}", error.Description);
    }
};

When I change the inlined handler to an method, the error goes away. What am I missing here?

private void CompletionWithItemsHandler(NSString activityType, bool completed, NSExtensionItem[] returnedItems, NSError error)
{
    if (error != null)
    {
        logger.Error("Error: {0}", error.Description);
    }
}

Solution

  • It turns out that the code is perfectly fine.

    The developer of Xamarin.iOS have turned on Nullable reference types while not completely marking all nullable params correctly. It seems to be in there for quite a while, but the new version of Rider now also inspects library code that it previously apparently has not.