0

I have the following exposed endpoint in my API:

    [HttpGet]
    [ActionName("GetResponse")]
    public string GetResponse()
    {

        ClientCertificate = LoadCertificate(); //confirmed this works fine

        if (ClientCertificate != null)
        {
            BasicSample(AuthenticationMethod.ClientCertificate).Wait();
        }
        return "finished";
     }

    /// <summary>
    /// Runs the basic query with no server/client query text
    /// </summary>
    private static async Task BasicSample(AuthenticationMethod authMethod)
    {
        using (var client = DgrepClientFactory.GetFactoryMethod(authMethod)())
        {
            var result = await client.GetRowSetResultAsync(SampleInputWithoutSvrQuery, CancellationToken.None);
        }
    }

Declared beforehand:

    /// <summary>
    /// A sample query input without server query text.
    /// </summary>
    private static readonly QueryInput SampleInputWithoutSvrQuery = new QueryInput
    {
        MdsEndpoint = new Uri("https://myendpoint.net/"),
        EventFilters = new List<EventFilter>
        {
            new EventFilter { NamespaceRegex = "^TestLogs$", NameRegex = "^Telemetry$" },
        },
        StartTime = StartTime,
        EndTime = StartTime + TimeSpan.FromMinutes(45),
        ServerQuery = "where property == \"TestProperty\")",
        MaxRowCount = 750000
    };



    private static X509Certificate2 ClientCertificate = null;

However, I'm hitting the following error whenever BasicSample is called via GetResponse(): "Exception": "One or more errors occurred.", "ExceptionType": "System.AggregateException",

 "CallStack": "   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n   at System.Threading.Tasks.Task.Wait()\r\n   at Windows.Services.DeliveryCatalog.ContentViewerApi.Controllers.ADUReliabilityController.GetResponse()\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()"

When I run this exact same code via a console app instead of via a REST API, it works fine.

   private static async Task BasicSample(AuthenticationMethod authMethod)
    {
        Console.WriteLine($"== Starting {nameof(BasicSample)} ({authMethod}) ==");
        using (var client = DgrepClientFactory.GetFactoryMethod(authMethod)())
        {
            var result = await client.GetRowSetResultAsync(SampleInputWithoutSvrQuery, CancellationToken.None);
            PrintRowSet($"{nameof(BasicSample)}_{authMethod}", result.RowSet);
        }
        Console.WriteLine($"== {nameof(BasicSample)} ({authMethod}) completed successfully ==");
    }



    public static void Main(string[] args)
    {
        if (ParseArguments(args))
        {
            ClientCertificate = LoadCertificate();
            if (ClientCertificate != null)
            {
                Console.WriteLine("\n= Samples using client certificate authentication =\n");
                BasicSample(AuthenticationMethod.ClientCertificate).Wait();
            }
         }
      }

Any ideas why the REST API throws that stack trace even though it is doing the same exact thing as the console app?

EDIT: (Attempting to make GetResponse async and instead doing an await BasicSample. It leads to the following error stack trace:)

"CallStack": "at Microsoft.Azure.Monitoring.DGrep.SDK.DGrepClientLogger.Info(String message, Guid queryId, String method, String filePath, Int32 lineNumber)
   at Microsoft.Azure.Monitoring.DGrep.SDK.DGrepClient.<StartQueryAsync>d__13.MoveNext() in X:\\bt\\1067307\\repo\\src\\sdk\\DGrep\\DGrepClient.cs:line 201
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Monitoring.DGrep.SDK.DGrepClientExtensions.<GetRowSetResultAsync>d__2.MoveNext() in X:\\bt\\1067307\\repo\\src\\sdk\\DGrep\\DGrepClientExtensions.cs:line 65
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Windows.Services.DeliveryCatalog.ContentViewerApi.Controllers.ADUReliabilityController.<BasicSample>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Windows.Services.DeliveryCatalog.ContentViewerApi.Controllers.ADUReliabilityController.<GeResponse>d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__6.MoveNext()"
user2463517
  • 197
  • 1
  • 5
  • 14
  • 2
    Why are you using `.Wait` instead of making the method asynchronous? `public async Task GetResponse() { ... await BasicSample(AuthenticationMethod.ClientCertificate); ...}` – Igor Jul 14 '20 at 16:37
  • 1
    As a side note it is standard practice to name methods that return Task or Task with Async as the method name suffix. Example: `BasicSampleAsync` instead of `BasicSample` – Igor Jul 14 '20 at 16:38
  • @Igor I just attempted to make GetResponse async and instead await BasicSample. It still throws an error, although a different stack trace: (Putting stack trace in question as edit since it is long) – user2463517 Jul 14 '20 at 16:42
  • 1
    I never know whether to expand the call stack entirely into its readable form (with line breaks) or not when posting questions on SO. It's compact and all the data is there, but a little bit frustrating to actually read. – Wyck Jul 14 '20 at 16:42
  • @Wyck Right.. I wish I knew a better option here. It seemed like the best way to put it in. – user2463517 Jul 14 '20 at 16:44
  • You should also have an Exception Type as well as an Exception Message. Please include that information in the question as the stack trace will only take you so far. – Igor Jul 14 '20 at 17:33
  • @Igor it is "Exception": "One or more errors occurred.", "ExceptionType": "System.AggregateException". This is followed by the stack trace – user2463517 Jul 14 '20 at 18:12
  • 1
    Call `Flatten()` on an `AggregateException` to see possible inner exceptions. – Peter Jul 14 '20 at 19:22

0 Answers0