Problem with async task

1

I'm bumping my head to be able to solve it but I can not, the error you're giving is

An asynchronous module or handler completed while an asynchronous operation was still pending.

source error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

I am sending a request to generate a ticket, but this is an asynchronous error. I'm using the Fluent plugin for this.

code:

public async Task<FileStreamResult> Teste(){
    var response = url.WithHeaders(
        new
        {
            Authorization =
            "Basic " + Convert.ToBase64String(
                Encoding.UTF8.GetBytes(ApiKey + ":" + Password)),
            ContentType = "application/x-www-form-urlencoded"
        }).PostUrlEncodedAsync(boleto).Result;

    var pdfBytes = response.Content.ReadAsByteArrayAsync().Result;
    pdfBytesResult = pdfBytes;
    MemoryStream ms = new MemoryStream(pdfBytesResult);
    return new FileStreamResult(ms, "application/pdf");
}

The problem only occurs when the site is in production (IIS), when the site does not happen

    
asked by anonymous 01.09.2017 / 16:31

2 answers

-1

The problem was not in the code but in the proxy, which was blocking external access.

    
01.09.2017 / 17:44
2

You need to use await to wait for execution of ReadAsByteArrayAsync

var pdf = await response.Content.ReadAsByteArrayAsync();
    
01.09.2017 / 16:47