Skip to content

Not possible to Substitute.For(new[] { typeof(ISomething) }, null) in 4.3.0 #685

@appel1

Description

@appel1

private static bool HasItems<T>(T[]? array) => array?.Length != 0;

It was changed from:

private static bool HasItems<T>(T[]? array)
{
    return array != null && array.Length > 0;
}

to

private static bool HasItems<T>(T[]? array) => array?.Length != 0;

Those two statements behave differently if array is null. The old code resulted in false but the new code returns true in this case. I don't think that was an intentional change?

  Message: 
NSubstitute.Exceptions.SubstituteException : Can not provide constructor arguments when substituting for an interface.

  Stack Trace: 
CastleDynamicProxyFactory.VerifyNoConstructorArgumentsGivenForInterface(Object[] constructorArguments)
CastleDynamicProxyFactory.CreateProxyUsingCastleProxyGenerator(Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments, IInterceptor[] interceptors, ProxyGenerationOptions proxyGenerationOptions)
CastleDynamicProxyFactory.GenerateTypeProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments)
CastleDynamicProxyFactory.GenerateProxy(ICallRouter callRouter, Type typeToProxy, Type[] additionalInterfaces, Object[] constructorArguments)
SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments, Boolean callBaseByDefault)
SubstituteFactory.Create(Type[] typesToProxy, Object[] constructorArguments)
Substitute.For(Type[] typesToProxy, Object[] constructorArguments)

Changing it to this should fix it:

private static bool HasItems<T>(T[]? array) => array?.Length > 0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions