The delegate does not contain a definition for CreateDelegate in the .net kernel

I am trying to use delegates for reflection in a dotNet network application. Below is a sample code.

Action action = (Action) Delegate.CreateDelegate(typeof(Action), method) 

The compiler produces the following error:

 'Delegate' does not contain a definition for 'CreateDelegate' ConsoleApp2..NETCoreApp,Version=v1.0' 

Is there any work to create delegates in .net Core?

+5
source share
1 answer

Use MethodInfo.CreateDelegate instead.

 MethodInfo methodInfo = target.GetType().GetMethod(nameof(FooMethod)); Action action = (Action) methodInfo.CreateDelegate(typeof(Action), target); 
.NET Core 2.0 expected to return

Delegate.CreateDelegate : .NET API Catalog

+4
source

All Articles