vc3/Afterthought — Issue #31: Method delegate type selection logic incorrect?
Author: hiredgunhouse
Created: 2011-11-23 15:17:23+00:00
State: open

See this code:
'''
// Determine if the target method uses the object array or explicit parameter syntax
if (parameters[1].ParameterType == typeof(string) && // Method Name
parameters[delegateType.HasFlag(MethodDelegateType.WithContext) && !delegateType.HasFlag(MethodDelegateType.Before) ? 3 : 2].ParameterType == typeof(object[]) && // Method Parameters
(!delegateType.HasFlag(MethodDelegateType.HasResultParameter) || (parameters[parameters.Length - 1].ParameterType == typeof(object) && method.ReturnType == typeof(object)))) // Method Result
delegateType |= MethodDelegateType.ArraySyntax;
else
delegateType |= MethodDelegateType.ExplicitSyntax;
'''
What happends if you have a method with just one parameter which is of type string and you create a delegate for it?
It treats that deletage as ArraySyntax type which is cause ArrayIndexOutOfBounds exception right in the if statement.

I believe that the:
if (parameters[1].ParameterType == typeof(string) && // Method Name
assumption is incorrect.