Program terminates when calling WorkItemTrackingHttpClient.QueryByWiqlAsyc()

96 Views Asked by At

I am working on a program that gets a list of workitems in the committed state from Azure DevOps for a specific area path and iteration path. My code is based on an example found at the following link: https://learn.microsoft.com/en-us/azure/devops/integrate/quickstarts/work-item-quickstart?view=azure-devops

The issue I am running into is when QueryByWiqlAsync() is called, the program terminates and there are no errors for why it terminated. Below is the code in question. I tried calling QueryByWiqlAsync() with and without the ConfigureAwait(false) and that did not seem to make a difference. Any suggestions on what to try or what to fix are appreciated.

static async void GetWorkItemsToTaskFromADO(string tfs_project, string accessToken)
{
    var credentials = new VssBasicCredential(string.Empty, accessToken);

    var wiql = new Wiql()
    {
        Query = @"Select [Id] From WorkItems WHERE [System.TeamProject] = 'SampleADOProject' AND [System.AreaPath] = 'Sample\ADO\AreaPath' AND [System.IterationPath] = 'Sample\ADO\IterationPath' AND [System.State] = 'Committed'"
    };

    using (var httpClient = new WorkItemTrackingHttpClient(new Uri(tfs_project), credentials))
    {
        try
        {
            var result = await httpClient.QueryByWiqlAsync(wiql).ConfigureAwait(false);
            var ids = result.WorkItems.Select(item => item.Id).ToArray();
            var fields = new[] { "System.Id", "System.Title", "System.State" };
            var workItems = await httpClient.GetWorkItemsAsync(ids, fields, result.AsOf).ConfigureAwait(false);
            // output results to test what came back...
            foreach (var workItem in workItems)
            {
                Console.WriteLine(
                    "{0}\t{1}\t{2}",
                    workItem.Id,
                    workItem.Fields["System.Title"],
                    workItem.Fields["System.State"]
                );
            }
        }
        catch(Exception ex)
        {
            Console.WriteLine(ex.Message);
            Console.Read();
        }
    }
}

0

There are 0 best solutions below