Skip to content

Remove CS1717 warning after not null assertion #46583

Answered by RikkiGibson
neoaisac asked this question in General
Discussion options

You must be logged in to vote

Re: a ! suppression operator updating the operand state to not-null. I assume the C# language team has considered this question at length and is unlikely to change the behavior. /cc @jcouv who may be able to provide context on that specifically.

It looks like Nunit is unable to put [NotNull] on the parameter of their Assert.NotNull method because the method doesn't throw on a null argument in the context of a lambda passed to Assert.Multiple. You may be able to solve your problem by introducing API within your own test project similar to the following:

using System.Diagnostics.CodeAnalysis;

void AssertNotNull([NotNull] object? arg)
{
    Assert.NotNull(arg);
    if (arg is null)
    {

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by jmarolf
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #46583 on September 22, 2020 21:03.