internal async Task <MethodInfo> GetFunctionTargetAsync()
        {
            try
            {
                return(await _functionLoader.GetFunctionTargetAsync().ConfigureAwait(false));
            }
            catch (CompilationErrorException exc)
            {
                TraceOnPrimaryHost("Function compilation error", TraceLevel.Error);
                TraceCompilationDiagnostics(exc.Diagnostics, LogTargets.User);
                throw;
            }
            catch (CompilationServiceException exc)
            {
                const string message = "Compilation service error";
                TraceWriter.Error(message, exc, _compilationService.GetType().Name);
                Logger?.LogError(message);

                // Compiler errors are often sporadic, so we'll attempt to reset the loader here to avoid
                // caching the compiler error and leaving the function hopelessly broken
                if (++_compilerErrorCount < 3)
                {
                    _functionLoader.Reset();

                    const string resetMessage = "Function loader reset. Failed compilation result will not be cached.";
                    TraceWriter.Info(resetMessage);
                    Logger?.LogError(resetMessage);
                }
                throw;
            }
        }