1

I'm trying to return a list of followed users from the Instagram API. I'm on a sandbox account using the InstaSharp wrapper for .NET.

The action method is being called after user is authenticated.

public ActionResult Following()
{
    var oAuthResponse = Session["InstaSharp.AuthInfo"] as OAuthResponse;

    if (oAuthResponse == null)
    {
        return RedirectToAction("Login");
    }

    var info = new InstaSharp.Endpoints.Relationships(config_, oAuthResponse);

    var following = info.Follows("10").Result;

    return View(following.Data);
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472
tqrecords
  • 542
  • 1
  • 5
  • 20
  • Show the whole Action method and also how it is being called. Most likely you are mixing async and blocking calls ie: `.Result` which runs the risk of causing a deadlock – Nkosi Nov 05 '17 at 01:09

1 Answers1

1

Try making the method async all the way through instead of making the blocking call .Result which runs the risk of causing a deadlock

public async Task<ActionResult> Following() {
    var oAuthResponse = Session["InstaSharp.AuthInfo"] as OAuthResponse;

    if (oAuthResponse == null) {
        return RedirectToAction("Login");
    }

    var info = new InstaSharp.Endpoints.Relationships(config_, oAuthResponse);

    var following = await info.Follows("10");

    return View(following.Data);
}

depending on how info.Follows was implemented.

Looking at the Github repo, the API internally makes a call to a method defined like this

public static async Task<T> ExecuteAsync<T>(this HttpClient client, HttpRequestMessage request)

Which looks like your smoking gun as calling .Result higher up the call stack on this task would result in your experienced deadlock.

Reference Async/Await - Best Practices in Asynchronous Programming

Nkosi
  • 235,767
  • 35
  • 427
  • 472
  • okay, Data is returning 0 results. Not sure if this is a limitation with sandbox apps.. – tqrecords Nov 05 '17 at 01:21
  • 1
    @Tariq But it has stopped hanging? whick was the original problem right? I do not know enough about that API. I was just identifying what are the known causes of the problem you described originally. – Nkosi Nov 05 '17 at 01:22