Skip to content

Assert.That on a null non-generic IEnumerable throws ArgumentNullException, so IsNull() cannot pass #7698

Closed

Description

@knutwannheden

Assert.That(x).IsNull() throws ArgumentNullException when x is a null non-generic IEnumerable, so the assertion can never pass. With TUnit 1.79.0:

IEnumerable? renderings = null;
await Assert.That(renderings).IsNull();   // ArgumentNullException: Value cannot be null. (Parameter 'source')

The generic and object overloads accept the same null value:

IEnumerable<int>? items = null;
await Assert.That(items).IsNull();        // passes

object? value = null;
await Assert.That(value).IsNull();        // passes

The overload taking a non-generic IEnumerable also declares its parameter non-nullable, so the compiler warns (CS8604) at the call above. Casting the value to object? makes the assertion pass.

Expected: IsNull() passes for a null non-generic IEnumerable, as it does for IEnumerable<T>. Other assertions on a null value should fail with an assertion failure rather than ArgumentNullException.

Found while migrating an xUnit suite, where Assert.Null(renderings) on a non-generic IEnumerable passed.

Activity

  1. added
    bugSomething isn't working
    P2Medium: edge case, mode divergence, flaky test, or workaround exists
    on Nov 9, 2026
  2. added a commit that references this issue on Nov 16, 2026
    2abdd8e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions