Skip to content

It.IsAny<StructObject>() isn't  #1466

Open
@MatthewGaraffa

Description

@MatthewGaraffa

Describe the Bug

It.IsAny<TValue>() doesn't support TValue's of type Struct.

I know this is an issue with the type being a Struct because changing that Struct to a Class allows the test to pass properly.

Steps to Reproduce

stubClass.VerifySet(o => o.Property = It.IsAny<StructObject>(), Times.Once);

Expected Behavior

It.IsAny<StructObject>() should behave the same as any It.IsAny<Class>().

Exception with Stack Trace

System.ArgumentException : Could not determine the correct positions for all argument matchers (1 in total) used in a call to this method: IClass.set_Property.
This could be caused by an unrecognized type conversion, coercion, narrowing, or widening, and is most likely a bug in Moq. Please report your use case to the Moq team.

Stack Trace: 
  ActionObserver.<ReconstructExpression>g__GetArgumentExpressions|0_0[T](Invocation invocation, Match[] matches) line 197
  ActionObserver.ReconstructExpression[T](Action`1 action, Object[] ctorArgs) line 53
  Mock`1.VerifySet(Action`1 setterExpression, Func`1 times) line 1234
  ClassTests.ButtonClick_BadResult_ReturnsFailure() line 51
  RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
  MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)

Version Info

Moq 4.20.70, published November 28, 2023

Additional Info

N/A

Back this issue
Back this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions