Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MissingMethodException when Verify Method with Array of ValueTuple #1154

Closed
Ben-Ebsta opened this issue Apr 9, 2021 · 3 comments
Closed

Comments

@Ben-Ebsta
Copy link

To be honest, I'm not sure if you actually support this, but here is what I am trying to do:

I have a logger class that I want to mock and it has a method Fatal that I would like to verify. I am having trouble matching the method signature and I think it is because it takes an array of ValueTuples.

void Fatal(string message, params (string Name, object Value)[] attributes);

Here is what I tried:

mockLogger.Verify(x => x.Fatal(It.IsAny<string>(), It.IsAny<(string Name, object Value)[]>()), Times.Once);

This compiles, but when I run my unit test it throws the MissingMethodException exception.

@stakx
Copy link
Contributor

stakx commented Apr 9, 2021

I cannot reproduce the error you're reporting:

using Moq;

var mock = new Mock<ILogger>();
mock.Verify(m => m.Fatal(It.IsAny<string>(), It.IsAny<(string Name, object Value)[]>()), Times.Once);

public interface ILogger
{
    void Fatal(string message, params (string Name, object Value)[] attributes);
}

When run, the above program causes the following exception (as it should):

Moq.MockException:
Expected invocation on the mock once, but was 0 times: m => m.Fatal(It.IsAny<string>(), It.IsAny<(string, object)[]>())

Performed invocations:

   Mock<ILogger:1> (m):
   No invocations performed.

Please provide complete, but minimal repro code; otherwise I'm going to close this issue in a few days' time.

@Ben-Ebsta
Copy link
Author

@stakx thanks for the quick reply. I appreciate you trying this out and the fact you couldn't reproduce is valuable information. In trying to create a minimal repo code, somehow the error disappeared for me too. I will dig a bit deeper and try and work out what exactly is causing the exception.

@Ben-Ebsta
Copy link
Author

Ben-Ebsta commented Apr 12, 2021

@stakx it turns out that the reason I was getting this error, was because the NuGet package System.ValueTuple v4.5.0 was installed and in the app.config file there was also the following:

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
      </dependentAssembly>
      ...
    </assemblyBinding>
  </runtime>
</configuration>

After I removed the assembly binding redirect from the app.config it all worked fine. However, just to make sure I also uninstalled the NuGet package as well since I believe ValueTuples are now built-in right?

Thanks again for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants