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

System.MissingMethodException in Moq #555

Closed
stevejbrother opened this issue Dec 17, 2017 · 2 comments
Closed

System.MissingMethodException in Moq #555

stevejbrother opened this issue Dec 17, 2017 · 2 comments

Comments

@stevejbrother
Copy link

I opened up a question on StackOverflow where I'm getting the MissingMethodException. I'm using MSTest build where I have an overload method to Create or Update some items in an MySQL Database where I need to include transactions. Given that MySQL does not do nested transactions, I had to do an overload of methods. Problem is, even before I do a unit test and trying to set up the Moq, I get MissingMethodException thrown; yet, when I run it using MySQL database to test it out, it works fine.

This is what I have:
`Mock _ProductRepositoryMoq = new Mock();

        _ProductRepositoryMoq.Setup(r => r.CreateNewProductItem(It.IsAny<ProductExt>()))
            .ReturnsAsync((ProductExt p) =>
            {
                p.ID = productList.Last().ID + 1;
                return p.ID;
            });
        _ProductRepositoryMoq.Setup(r => r.CreateNewProductItem(It.IsAny<ProductExt>(), It.IsAny<MySqlConnection>(), It.IsAny<MySqlTransaction>()))
            .ReturnsAsync((ProductExt p, MySqlConnection c, MySqlTransaction t) =>
            {
                p.ID = productList.Last().ID + 1;
                return p.ID;
            });`

Now the first method with just a ProductExt parameter works fine in the Moq, but it's the second overloaded method that's giving me the MissingMethodException but as I stated, it is indeed working and I have verified through the database that data is being inserted and/or modified.

Something is telling me that there's a problem with Moq or I'm not setting this up correctly. How is it that it's working with the database, but not with a Moq?

Did I really find a bug, or am I doing a newbie mistake, and if so, where did I go wrong and how do I set it up correctly?

@stakx
Copy link
Contributor

stakx commented Dec 17, 2017

I saw your question on Stack Overflow, and I commented there that the error you're seeing isn't reproducible with just the code shown.

Until you have ruled out some DLL versioning problem, there's no reason to assume that the problem lies with Moq.

  • What version of Moq does your project reference?
  • What version of Moq.dll do you actually find in your binaries folder?
  • Are there any other NuGet packages depending on Moq, and if so, what versions do they reference?
  • Do you have any assembly binding redirects set up in App.config or Web.config? Have you tried removing or updating them?
  • Have you tried deleting your solutions' binaries folders, clearing your NuGet package cache, then performing a package restore and rebuild?

If you've checked all of the above, found no inconsistencies or version conflicts, and you're still seeing the problem, then please post a small, standalone project (e. g. as a ZIP file) that exhibits the problem. Otherwise there's not much we can help you with.

@stakx
Copy link
Contributor

stakx commented Jan 4, 2018

Turns out this is possibly a duplicate of #566.

@stakx stakx added the duplicate label Jan 4, 2018
@devlooped devlooped locked and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants