question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArgumentException after upgrading from Moq 4.10.1 to 4.11 (and later)

See original GitHub issue

I have a mock that is created, using Autofixture.Moq nuget package, with:

var fixture = new Fixture();
fixture.Customize(new AutoMoqCustomization());
var myMock = fixture.Create<IMyInterface>()

That was working with Moq 4.10.1 but no more with Moq 4.11 and later.

But now, when calling a method on this mock, I’ve got the exception:

System.ArgumentException
Argument types do not match
   at ConstantExpression System.Linq.Expressions.Expression.Constant(object value, Type type)
   at void Moq.Mock.AddInnerMockSetup(Invocation invocation, object returnValue)
   at void Moq.Return.Handle(Invocation invocation, Mock mock)
   at void Castle.DynamicProxy.AbstractInvocation.Proceed()
   at Dictionary<int, CategoryResult[]> Castle.Proxies.ICoreServiceProxy.GetCategoryResultsFormattedForEntity(out long cacheRevision, Nullable<int> idAnalysis, int entityID, List<AttributeAndFormat> attributes, int beginPeriod, int endPeriod, Periodicity periodicitySelected, bool ignoreOutOfBounds, TalianceToken talianceToken, Nullable<int> idSnapshot)

Could you give me a clue from where the problem could come from?

I’m not really sure if it’s a AutoFixture.Moq problem (and need an update with newer moq releases) or a Moq regression… So including @stakx in the report.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pmiosseccommented, Feb 9, 2021

Giving another quick try to update from “4.10.1” to “4.16.0” and AutoFixture.AutoMoq from “4.11.0” to"4.15.0" and I still have the problem.

I have a better stacktrace:

System.ArgumentException
Argument types do not match
   at ConstantExpression System.Linq.Expressions.Expression.Constant(object value, Type type)
   at InvocationShape Moq.InvocationShape.CreateFrom(Invocation invocation) in C:/projects/moq4/src/Moq/InvocationShape.cs:line 31
   at void Moq.Behaviors.ReturnBaseOrDefaultValue.Execute(Invocation invocation) in C:/projects/moq4/src/Moq/Behaviors/ReturnBaseOrDefaultValue.cs:line 82
   at void Moq.Mock.Moq.IInterceptor.Intercept(Invocation invocation) in C:/projects/moq4/src/Moq/Interception/Mock.cs:line 34
   at void Moq.CastleProxyFactory+Interceptor.Intercept(IInvocation underlying) in C:/projects/moq4/src/Moq/ProxyFactories/CastleProxyFactory.cs:line 107
   at void Castle.DynamicProxy.AbstractInvocation.Proceed()

I don’t have a good understanding because that’s a big dirty test (not unit at all!!) but the behavior change is still there. I have to figure it out what is the real problem but that will require more investigation…

1reaction
aivascucommented, Dec 14, 2020

@jzabroski I have reproduced the setup from the original post with the latest AutoFixture and I could not reproduce the failure. I used a .NET Framework unit test project with the following dependencies.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AutoFixture" version="4.14.0" targetFramework="net472" />
  <package id="AutoFixture.AutoMoq" version="4.14.0" targetFramework="net472" />
  <package id="Castle.Core" version="4.4.0" targetFramework="net472" />
  <package id="Fare" version="2.1.1" targetFramework="net472" />
  <package id="Moq" version="4.11.0" targetFramework="net472" />
  <package id="MSTest.TestAdapter" version="2.1.1" targetFramework="net472" />
  <package id="MSTest.TestFramework" version="2.1.1" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.1" targetFramework="net472" />
</packages>

The following test fails.

[TestMethod]
public void MockCreationShouldFail()
{
    var fixture = new Fixture();
    fixture.Customize(new AutoMoqCustomization());
    Action act = () => fixture.Create<IMyInterface>();

    Assert.ThrowsException<Exception>(act);
}

public interface IMyInterface
{
}

Closing this issue. If anyone finds a reproducible example, feel free to reopen the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Moq Verify Not Working as Expected After Upgrading to . ...
After upgrading to .NET Core 3.1 and Moq Version 4.14.5, the verify method is failing saying the method specified hasn't been called (no...
Read more >
Moq/CHANGELOG and Moq Releases (Page 4) | LibHunt
After updating Moq from 4.10.1 to 4.11, mocking NHibernate session throws a System.NullReferenceException (@ronenfe, #955) ...
Read more >
Moq
ArgumentException : No protected method HasMethodWithRefParameter.RefMethod found whose signature is compatible with the provided arguments (int). mock.
Read more >
Firebase Apple SDK Release Notes - Google
Added a new dynamic property wrapper API that enables developers to configure UI components to automatically update when new configs are activated. (#10155) ......
Read more >
2020-July.txt
- CVE-2020-15025: Fixed an issue which remote attacker could have caused denial of service by consuming the memory when a CMAC key was...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found