2

I am integrating MailChimp API using ASYNC and JSON

****1 - Caller Section****

internal class MCReportsOverview
{
     internal async Task<ReportOverview_CampaignSpecific> CampaignSpecificOverviewAsync(string campaignId)
    {
        string endpoint = Authenticate.EndPoint(TargetTypes.reports, SubTargetType.not_applicable, SubTargetType.not_applicable, campaignId);

        var jsonTask= await BaseOperation.GetAsync<ReportOverview_CampaignSpecific>(endpoint);
        return  jsonTask;
    }
}

**** 2 - Called Section ****

F11 hangs on the last line and doesn't return value to #1. The data is all correct. The code for the called function is

public static async Task<T> GetAsync<T>(string endpoint) where T : class
{
    string content;
    using (HttpClient client = new HttpClient())
    {
        try
        {
            Authenticate.ClientAuthentication(client);
            content = await client.GetStringAsync(endpoint).ConfigureAwait(false);
        }
    }

    return JsonConvert.DeserializeObject<T>(content); // F11 hangs here and doesnt return to the calling function

}

Function Calling

This is how I am calling #1

MCCampaignsOverview overview = new MCCampaignsOverview();
var yy = overview.GetCampaignByIdAsync("aaaa1111").Result;
Manny
  • 29
  • 2
  • Can you cut this down to a simple [mcve] (i.e. remove `BaseOperation` and cut it down to the **fewest possible lines of code needed** to communicate with the MailChimp API)? – mjwills Mar 22 '18 at 00:53
  • Also see https://stackoverflow.com/questions/730250/is-there-a-difference-between-throw-and-throw-ex . – mjwills Mar 22 '18 at 00:56
  • 1
    This is unrelated to your issue, but you should know that it’s generally a bad idea to instantiate a new HttpClient for every request. See [here](https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/) – maccettura Mar 22 '18 at 01:19
  • 3
    If your code is hanging, it's almost certainly a deadlock. How are you calling these functions? Are you using async all the way or do you have a `.Result` call somewhere? – DavidG Mar 22 '18 at 01:24
  • I have removed some code and how its called in the Main – Manny Mar 22 '18 at 03:10
  • It doesn't seem _exactly_ like a [mcve] since I can't just copy and paste it into a console app and run it. – mjwills Mar 22 '18 at 06:05

0 Answers0