ref keyword in interface method declaration causes exception #42

Pjanssen opened this Issue Apr 9, 2013 · 3 comments

3 participants


I'm writing unittests for an application which makes use of a third party API, with some generated interfaces. I was getting some strange exceptions trying to create a mock object for a complex interface. After much digging, I found that one of these interfaces it extends has a declaration with a ref keyword in it:

public interface IReferenceMaker
   RefResult NotifyRefChanged(ref UIntPtr partID, RefMessage message);

When trying to create a mock object for this interface, an exception is thrown when accessing the Object property: ArgumentException: Type System.UIntPtr could not be converted to a OpCode.

Mock<IReferenceMaker> mockRefMaker = new Mock<IReferenceMaker>();
IReferenceMaker refMaker = mockRefMaker.Object;

Unfortunately I can't change the interface in any way, so I'm looking for a way to work around the issue on the Moq side.
Any ideas?

edit: I noticed in the stacktrace that the exception is thrown in Castle, so I submitted an issue report there too.

Moq Team member

It appears this was fix when upgrading to Castle 3.3.3 #204.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment