Awaiting simple Task<T> never continues

Viewed 45

I have a simple task meant to make a call to the Azure GraphAPI and return the logged in user. The query works and returns the info as expected. The problem is if I try to take that data, assign the data to an object and then return that object. When I do that, the code starts to execute the await graphclient.Me line but never continues. As if it is just waiting for the API to respond.

For some context, I want to return the results so I can use the returned UserModel as a property on a view model.

UserModel is just a simple class with two string properties.

public class UserModel
{
    public string FName { get; set; }
    public string LName { get; set; }
}

I make a call to the task:

 _loggedInUser = GetSignedInUserDetails().Result;

Below is that task that hangs up when trying to return type UserModel. If I modify the task to a void task, it executes without issue.

private async Task<UserModel>  GetSignedInUserDetails()
{
    GraphServiceClient graphClient = await GraphAPIServices
        .SignInAndInitGraph(AzureAppInfo.UserReadAll);

    UserModel loggedInUser = new UserModel();

    var user =  await graphClient.Me
        .Request()
        .GetAsync();

    loggedInUser.LName = user.GivenName;
    loggedInUser.FName = user.Surname;

    return loggedInUser; 
}

I'm sure I am missing something fundamental, I just don't know what it is.

0 Answers
Related