Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref keyword in interface method declaration causes exception #42

Closed
Pjanssen opened this issue Apr 9, 2013 · 4 comments
Closed

ref keyword in interface method declaration causes exception #42

Pjanssen opened this issue Apr 9, 2013 · 4 comments

Comments

@Pjanssen
Copy link
Contributor

Pjanssen commented Apr 9, 2013

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.

@kzu
Copy link
Member

kzu commented Apr 9, 2013

yuck, could you also post that question to the Castle DynamicProxy guys?

/kzu

Daniel Cazzulino

On Tue, Apr 9, 2013 at 2:54 PM, Pier Janssen notifications@git.luolix.topwrote:

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 mockRefMaker = new Mock();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?


Reply to this email directly or view it on GitHubhttps://github.com//issues/42
.

@Pjanssen
Copy link
Contributor Author

Pjanssen commented Apr 9, 2013

@dtuchlinsky
Copy link

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

@stakx
Copy link
Contributor

stakx commented Jun 22, 2017

@dtuchlinsky: Thanks for the hint. This was fixed back in version 4.2.1510.2205 (which was the first version based on Castle 3.3.3).

@stakx stakx closed this as completed Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants