Using reflection, I'm trying to create a delegate from a parameterless constructor like this:
Delegate del = GetMethodInfo( () => System.Activator.CreateInstance( type ) ).CreateDelegate( delType );
static MethodInfo GetMethodInfo( Expression<Func<object>> func )
{
return ((MethodCallExpression)func.Body).Method;
}
But I get this exception: "Cannot bind to the target method because its signature or security transparency is not compatible with that of the delegate type." What will work?
Note that CreateDelegate was moved, for this profile at least, since the previous version of .NET. Now it's on MethodInfo.