public override async Task RunAsync()

in src/DurableTask.Core/ReflectionBasedTaskActivity.cs [82:152]


        public override async Task<string> RunAsync(TaskContext context, string input)
        {
            var jArray = Utils.ConvertToJArray(input);

            int parameterCount = jArray.Count - this.genericArguments.Length;
            ParameterInfo[] methodParameters = MethodInfo.GetParameters();
            if (methodParameters.Length < parameterCount)
            {
                throw new TaskFailureException(
                    "TaskActivity implementation cannot be invoked due to more than expected input parameters.  Signature mismatch.")
                    .WithFailureSource(MethodInfoString());
            }

            Type[] genericTypeArguments = this.GetGenericTypeArguments(jArray);
            object[] inputParameters = this.GetInputParameters(jArray, parameterCount, methodParameters, genericTypeArguments);

            string serializedReturn = string.Empty;
            Exception exception = null;
            try
            {
                object invocationResult = InvokeActivity(inputParameters, genericTypeArguments);
                if (invocationResult is Task invocationTask)
                {
                    if (this.MethodInfo.ReturnType.IsGenericType)
                    {
                        await invocationTask;

                        Type returnType = Utils.GetGenericReturnType(this.MethodInfo, genericTypeArguments);
                        PropertyInfo resultProperty = typeof(Task<>).MakeGenericType(returnType).GetProperty("Result");
                        serializedReturn = this.DataConverter.Serialize(resultProperty.GetValue(invocationTask));
                    }
                    else
                    {
                        await invocationTask;
                        serializedReturn = string.Empty;
                    }
                }
                else
                {
                    serializedReturn = DataConverter.Serialize(invocationResult);
                }
            }
            catch (TargetInvocationException e)
            {
                exception = e.InnerException ?? e;
            }
            catch (Exception e) when (!Utils.IsFatal(e))
            {
                exception = e;
            }

            if (exception != null)
            {
                string details = null;
                FailureDetails failureDetails = null;
                if (context.ErrorPropagationMode == ErrorPropagationMode.SerializeExceptions)
                {
                    details = Utils.SerializeCause(exception, DataConverter);
                }
                else
                {
                    failureDetails = new FailureDetails(exception);
                }

                throw new TaskFailureException(exception.Message, exception, details)
                    .WithFailureSource(MethodInfoString())
                    .WithFailureDetails(failureDetails);
            }

            return serializedReturn;
        }