Home > Software engineering >  moq 4.18.0 doest allow me to use list.IsNullOrEmpty() from Castle.core.internal
moq 4.18.0 doest allow me to use list.IsNullOrEmpty() from Castle.core.internal

Time:01-10

when i update my unit test project to moq 4.18.0 or above, i get the following exception Could not load type 'Castle.Core.Internal.CollectionExtensions'. In my service class im using the static method IsNullOrEmpty from Castle.core.internal. Im not getting this issue for moq versions below 4.18.0.

the resolve the issue for now I'm just creating my own internal IsNullOrEmpty method.

Any Idea how to solve this exception from moq?

CodePudding user response:

As it was stated by Ralf the CollectionExtensions has been removed from the package.

The IsNullOrEmpty was implemented like this:

public static bool IsNullOrEmpty(this IEnumerable @this)
{
    return @this == null || @this.GetEnumerator().MoveNext() == false;
}

But you can implement like this as well

public static bool IsNullOrEmpty(this IEnumerable @this)
    => !(@this?.GetEnumerator().MoveNext() ?? false);
  • Related