Thursday, January 22, 2009

NMock2 RemotingException ByRef value type parameter cannot be null

OK this might be the most misleading error message I've seen. I cannot decide on how to describe it... What this means... or what this try to ...
Actually this happens when one of your mocked objects is mocking a method that returns something and your mocking doesn't return anything. Eeeeh - that was quite tricky. Got it?
Here is an example:
When I mock this method:
Public Class FacadeObject 
     Function CreateSomeThing(ByVal aName As String) As Long
               End Function

        End Class
by using the following code to do the mock 
Expect.Once.On(m_mockadFacadeObject).Method("CreateSomeThing")
an exception of RemotingException (ByRef value type parameter cannot be null) will be thrown.
Here is another description that you might find easier to understand

6 comments:

Anonymous said...

I guess you used the version from nmock.org, which is not maintained anymore.

Please try the version at http://sourceforge.net/projects/nmock2

Then you get an error stating that you have to set a return value.

happy mocking
Urs

Marcus said...

Thank you Urs!

I must confess that it was quite sloppy of me not to set a return value but with your new update that will be even easier to remember.

I really apprieate the feedback also.

Keep up the good work.

Anonymous said...

Thank you very much for this post. I kept on looking at the parameter value....your post helped me fix the problem.

Marcus said...

Hey - happy to help!
Even with this old post :)

Richard Howes said...

I've never seen the benefit of writing gibberish in an effort to teach anything to anyone. They came to your page looking for answers to something they don't understand. How does adding confusion help?

Marcus said...

@Richard.

Thank you for your kind reminder. I haven't looked through my posts (ca 800 of them) and check the jibberish level on each one.

This 3 year old one had slipped. Quite honestly I cannot remember what/how I wrote it.

I'll update it now.

Still.... 2 other people found it useful and the NMock team came back and helped me. So i wasn't a complete vast, don't you agree.

Again - thank you for the pointer for me to clean up some bad writing.