Open kmreid opened 6 years ago
I have 2 Child_Create methods with the same number of parameters, but different param types:
protected void Child_Create(IProduct product, int location, decimal quantity, ICustomer cust) { base.Child_Create(product, location, quantity, cust); } protected void Child_Create(int productId, int location, decimal quantity, ICustomer cust) { var prod = ProductLoader.Load(productId); base.Child_Create(prod, location, quantity, cust); }
My code creates the child like this:
public static T New(int productId, int locationId, decimal quantity = 1, ICustomer cust = null) { ... DataPortal.CreateChild<T>(productId, locationId, quantity, cust); ... }
This throws an exception:
System.InvalidCastException : Unable to cast object of type 'System.Int32' to type 'MyProject.IProduct'.
I removed the cust parameter from the 1st Child_Create method, and it works - it is able to find the correct Child_Create method (the 2nd one).
Why is this happening? Is the method caller using the number of parameters to identify the method to call, and ignoring the types?
It is possible that there's a bug in MethodCaller. I know the number of parameters factors into the code, but it also does (or should) look at the parameter types as well.
MethodCaller
I have 2 Child_Create methods with the same number of parameters, but different param types:
My code creates the child like this:
This throws an exception:
I removed the cust parameter from the 1st Child_Create method, and it works - it is able to find the correct Child_Create method (the 2nd one).
Why is this happening? Is the method caller using the number of parameters to identify the method to call, and ignoring the types?