Thursday, February 19, 2009

Rhino Mock Error - rhino mocks requires a return value or an exception to throw

Sometimes it's just a matter of googling the right thing. I was trying to show someone how easy it was to develop mocks to help test, and wouldn't you know it, I kept getting errors in my test harness that I couldn't figure out. I thought it was because we were testing an object with a read only property and using the AutoMockingUnityContainer, but when I was finally smart enough to google the real exception being thrown:

rhino mocks requires a return value or an exception to throw

It immediately led me to this wonderful solution.

Google FTW.


Ray Vega said...

Ah yes, that old familiar, dreaded Rhino Mocks exception. I have burned many an hour trying to debug my test code whenever I got that error. That exception is just one of example of why Rhino Mocks error messages tend to be hard to decode.

Be aware that that particular message does not necessarily indicate that Replay call is missing. As I have discovered, it could also mean that the wrong data type is being used in a Expect call.

dana said...


I have tried to open the link you posted but I get an error.
Can you please post the solution for that error?

Thank you

Antony said...

you need to call
mocks.Replay(object causing the error);
in order to get it to work.

Customer is always wrong said...

dead links FTW