'xunit Assert.NotNull() does not play nicely with C# nullable types

Assert.NotNull(res);
Assert.Equal(1, res.Foo); // CS8602 warning here

I'm using xunit.assert 2.4.1, .NET 6.0, VS 2022.

When "Ctrl+Click" navigating to the Assert.NotNull() source code I can see it defined as

public static void NotNull(object @object)

while I was actually expecting to see

public static void NotNull([NotNull] object? @object)

From the xunit source code one can see that nullable flavour of methods are used only when XUNIT_NULLABLE conditional compilation variable is enabled. Can it be that nuget downloaded "non-nullable" version of the xunit.assert package? How can we force a "nullable" version (built with the XUNIT_NULLABLE defined)?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source