-
-
Notifications
You must be signed in to change notification settings - Fork 794
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
System.InvalidCastException when invoking method that starts with "add" #82
Comments
I can reproduce this and have tracked it down to a problem with the way Moq detects event handler attach methods and other special method types. The key file is: Methods called 'add__' and 'remove__' will not work, this is case sensitive hence why 'Add' works. We will need to try and find a better way to detect if something is an event handler attach call. |
Maybe we can just try to cast and fallback to considering it a regular method oherwise? |
Shouldn't that be checking |
+1 to IsSpecialName. Shouldn't pass for a normal method named "add_*" |
Why we should restrict users in their naming style(i have a lot of legacy code and it might be painfull to change restricted names)? Can we mark all special method types with some attribute? |
it's been so many years and this has come up so rarely that I'd say it's a I recall now that we removed the check for IsSpecialName for compatibility The naming goes against anything in .NET conventions for public/protected /kzu Daniel Cazzulino On Sun, Feb 9, 2014 at 11:56 PM, F0b0s notifications@github.com wrote:
|
Aha, I was mocking a web service with add_* method names and came across this issue :) |
Regular methods with |
Hello, I faced with the problem when i used Moq.
I wrote the simple test
When i call
mock.Object.add_info("asd");
it throws
System.InvalidCastException : Не удалось привести тип объекта "System.String" к типу "System.Delegate".
в Moq.AddActualInvocation.HandleIntercept(ICallContext invocation, InterceptStrategyContext ctx)
в Moq.Interceptor.Intercept(ICallContext invocation)
в Castle.DynamicProxy.AbstractInvocation.Proceed()
в Test.Class1.Test_add_info() в Class1.cs: line 22
Sorry, i have Russian VS, it says: "Can't cast System.String to System.Delegate". But, when i call
mock.Object.Object.Add_info("asd");
string, it works.
I use VS 2012, .NET4.5. Nuget packages - NUnit, Moq(v.4.2.1312.1622). The Code was runned from Resharper test runner.
The text was updated successfully, but these errors were encountered: