This is because, in the depths of the comparison logic of the collection, the Fluent Assertion uses the following code
for (int index = 0; index < expectedItems.Length; index++)
{
verification.ForCondition((index < actualItems.Length) && actualItems[index].Equals(expectedItems[index]))
.FailWith("Expected " + Verification.SubjectNameOr("collection") +
" to be equal to {0}{reason}, but {1} differs at index {2}.", expected, Subject, index);
}
in the code above expectedItemsand actualItems- your lists
Now think about what will happen during the second iteration, when (part below) is done?
actualItems[index].Equals(expectedItems[index])
which actualItems[1]is nullwhy it throws a null reference exception
source
share