InvalidOperationException instead of meaningful exception

115 views
Skip to first unread message

Iurii Gazin

unread,
Oct 22, 2013, 8:56:27 AM10/22/13
to rhino...@googlegroups.com
Hi,

I'm receiving InvalidOperationException in the attached code example, using last rhino mocks.
Here is the stacktrace:
at System.Reflection.RuntimeMethodInfo.GetGenericMethodDefinition()
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.MethodsEquals(MethodInfo method, ProxyMethodExpectationTriplet triplet)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.GetAllExpectationsForProxyAndMethod(Object proxy, MethodInfo method)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.CalcExpectedAndActual.Calculate(Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.UnexpectedMethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.DoGetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.MethodRecorders.MethodRecorderBase.GetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args)
at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args)
at Rhino.Mocks.Impl.Invocation.Actions.RegularInvocation.PerformAgainst(IInvocation invocation)
at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IDbHandlerProxy6d12ffc56cb147579f1dff408afd8d46.IDbHandler.OpenUoW<T>()
at ConsoleApplication1.UnitTest.MethodName() in UnitTest.cs: line 28

I know that my expectations are not actually right - I set an expectation onto non-generic method, but call generic method. Though I would expect to receive more meaningful exception from Rhino.Mock
I've caught this while debugging my test for the real application, and spent a lot of time debugging Rhino.Mocks while I figured out the error.
It looks like the method in Rhino.Mocks: UnorderedMethodRecorder.MethodsEquals(MethodInfo method, ProxyMethodExpectationTriplet triplet)
has this code:
  if(method.IsGenericMethod==false)
                                return triplet.Method == method;
                        return triplet.Method.GetGenericMethodDefinition() == method.GetGenericMethodDefinition();

which actually does not count a situation when method is generic, but triplet.Method is not - this is exactly my situation. Call to triplet.Method.GetGenericMethodDefinition() fails because of that.
There should be one additional check, like this:
if (method.IsGenericMethod != triplet.Method.IsGenericMethod)
                     return false;

If I am right, and there is no catch, where should I report this or make a pull request? Looks like https://github.com/ayende/rhino-mocks is abandoned.

UnitTest.cs

haifisch

unread,
Oct 22, 2013, 10:28:03 AM10/22/13
to rhino...@googlegroups.com
Hi Iurii,

just use the "git-hub" principle - just commit the change to your own branch - I'm sure that other users/maintainers will merge your changes into their own branches if you've submitted something useful.

Best regards,

Andreas

haifisch

unread,
Oct 23, 2013, 10:03:39 AM10/23/13
to rhino...@googlegroups.com
Just take a look how active many maintainers are...

https://github.com/ayende/rhino-mocks/network

Br,

Andreas
Reply all
Reply to author
Forward
0 new messages