If you read the documentation for Expression.GetDelegateType() , you will see that the return type should be the last argument.
This means that this code should work:
var tArgs = new List<Type>(); foreach (var param in method.GetParameters()) tArgs.Add(param.ParameterType); tArgs.Add(method.ReturnType); var delDecltype = Expression.GetDelegateType(tArgs.ToArray()); return Delegate.CreateDelegate(delDecltype, method);
This code only works for static methods. If you want to create a delegate from an instance method, you need to provide the instance on which you want to call the method. To do this, change the last line to:
return Delegate.CreateDelegate(delDecltype, instance, method);
svick source share