-
-
Notifications
You must be signed in to change notification settings - Fork 802
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
NullReferenceException thrown by Microsoft.CSharp when using Generic Interfaces and Dynamic #114
Comments
» dynamic o = obj; var output = o.DoStuff(input); Why make obj dynamic? If you just invoke obj.DoStuff(input) it should just /kzu from mobile |
The code above is just to reproduce the issue. In the real application I'm using dynamic for implementing a multiple-dispatch pattern (visitor..), and stumbled on this error when unit testing it. I have multiple DoStuff() methods, each taking in a specialization of IInterface as its parameter. Using dynamic allows me to invoke the correct DoStuff method based on the runtime type of the IInterface object. I can post a longer sample that's closer to my application if that helps. |
@AmitGee: Moq actually handles this just fine. You might have noticed that the exception does not get thrown by the mock invocation, but by the
That is, you have received a return value from the mock, and it is stored in What happens next is that the Dynamic Language Runtime cannot convert the value in |
I posted this to code.google.com (#376) before realising that the site had moved. The following code produces a NullRef exception
I'm using Win7, Moq 4.2.1402.2112, .NET 4.5.1
The exception occurs when using a mock of the generic interface, when the type argument is of type object. It doesn't occur when:
The full stack trace of the error is below the code.
Stack trace:
The text was updated successfully, but these errors were encountered: