I am loading an assembly and calling a static method that will create a new object of type “MyClass1” (this type is specified at runtime) through reflection using MethodInfo
As an enhancement to the accepted answer, you can avoid the blocking by awaiting the Task
in between:
var task = (Task)mi.Invoke(obj, null);
await task;
var result = task.GetType().GetProperty("Result").GetValue(task);
Of course this will be properly asynchronous only if all methods up the call stack are marked async
and you're using await
instead of .Result
everywhere.