1
I’m banging my head to solve but I can’t, the mistake 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 billet, but it is asynchronous error. I am using the plugin Fluent for that reason
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 local the same does not happen
Try never to use
.Result
of aTask
when you want to work asynchronously, in such cases you are forcing the code to be synchronous, and forcing something synchronous into something asynchronous worsens the performance, it is worse than working directly with synchronism.– Gabriel Katakura