title: HttpClient - Request was canceled - Timeout of 100 seconds elapsing
body: <p>I am using a blazor web assembly project followed by a asp.net core web api and a shared project. When running my two projects and pulling up post man to perform a GET request <code>https://localhost:5011/api/WebReport/GatherAllReports</code> it hits the <code>ReporterRepository</code> from the blazor web assembly and when it hits the very first line <code>var response</code> it stays on that line then eventually after a really long time it says on postman...</p>
  <p><strong>System.Threading.Tasks.TaskCanceledException: The request was canceled due to the configured HttpClient.Timeout of 100 seconds elapsing.</strong></p>
  <blockquote>
  <p>---&gt; System.TimeoutException: The operation was canceled.</p>
  <p>---&gt; System.Threading.Tasks.TaskCanceledException: The operation was canceled.</p>
  <p>---&gt; System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..</p>
  <p>---&gt;
  System.Net.Sockets.SocketException (995): The I/O operation has been
  aborted because of either a thread exit or an application request.<br />
  --- End of inner exception stack trace ---</p>
  </blockquote>
  <blockquote>
  <p>at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)</p>
  <p>at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)</p>
  <p>at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](TIOAdapter adapter, Memory`1 buffer)</p>
  <p>at System.Net.Http.HttpConnection.FillAsync(Boolean async)</p>
  <p>at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed)</p>
  <p>at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)</p>
  <p>--- End of inner exception stack trace ---</p>
  <p>at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)</p>
  <p>at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)</p>
  <p>at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)</p>
  <p>at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)</p>
  <p>at Microsoft.Extensions.Http.Logging.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</p>
  <p>at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)</p>
  <p>at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken)</p>
  <p>--- End of inner exception stack trace ---</p>
  </blockquote>
  <p>and much more other messages returned in postman.</p>
  <p><strong>Is there a reason why this is occurring whenever I call the route endpoint for my web api controller?</strong></p>
  <p>Web API Controller:</p>
  <pre><code>using BlazorReports.Services; // this contains the `ReporterRepository.cs` file
  
  [Route(&quot;api/[controller]&quot;)]
  [ApiController]
  public class WebReportController : ControllerBase
  {
      
      private readonly ReporterRepository_repo;
  
      public WebReportController (ReporterRepository repo)
      {
          _repo = repo;
      }
  
      [HttpGet]
      [Route(&quot;GatherAllReports&quot;)]
      public async Task&lt;IActionResult&gt; Get()
      {
          var reportValues = await _repo.GetAll();
          return Ok(reportValues);
      }
  
  }
  </code></pre>
  <p><code>startup.cs</code> for web api:</p>
  <p>public class Startup
  {
  public Startup(IConfiguration configuration)
  {
  Configuration = configuration;
  }</p>
  <pre><code>public IConfiguration Configuration { get; }
  
  // This method gets called by the runtime. Use this method to add services to the container.
  public void ConfigureServices(IServiceCollection services)
  {
  
      services.AddControllers();
      services.AddSwaggerGen(c =&gt;
      {
          c.SwaggerDoc(&quot;v1&quot;, new OpenApiInfo { Title = &quot;WebAPI&quot;, Version = &quot;v1&quot; });
      });
      services.AddDbContext&lt;ReportContext&gt;(options =&gt;
            options.UseSqlServer(Configuration.GetConnectionString(&quot;Default&quot;)));
  
      services.AddScoped&lt;IReporterRepository, ReporterRepository&gt;();
  
      services.AddHttpClient&lt;IReporterRepository, ReporterRepository&gt;(client =&gt;
          {
              client.BaseAddress = new Uri(&quot;https://localhost:5011/&quot;);
          });
  
      services.AddHttpContextAccessor();
  }
  
  // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  {
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
          app.UseSwagger();
          app.UseSwaggerUI(c =&gt; c.SwaggerEndpoint(&quot;/swagger/v1/swagger.json&quot;, &quot;WebAPI v1&quot;));
      }
  
      app.UseHttpsRedirection();
  
      app.UseCors(opt =&gt; opt
            .AllowAnyMethod()
            .AllowAnyHeader()
            .SetIsOriginAllowed(origin =&gt; true) 
            .AllowCredentials()); 
  
      app.UseRouting();
  
      app.UseAuthorization();
  
      app.UseEndpoints(endpoints =&gt;
      {
          endpoints.MapControllers();
      });
  }
  </code></pre>
  <p>}</p>
  <p>In my blazor web assembly project:</p>
  <p><code>IReporterRepository.cs:</code></p>
  <pre><code>public interface IReporterRepository
  {
      Task&lt;List&lt;Reports&gt;&gt; GetAll();
  }
  </code></pre>
  <p><code>ReporterRepository.cs:</code></p>
  <pre><code>public class ReporterRepository: IReporterRepository
  {
     
      private readonly HttpClient _httpClient;
      private readonly JsonSerializerOptions _options;
  
      public ReporterRepository(HttpClient httpClient)
      {
          _httpClient = httpClient;
          _options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
      }
  
      public async Task&lt;List&lt;Reports&gt;&gt; GetAll()
      {
          var response = await _httpClient.GetAsync(&quot;/ReportsPage/GatherAllReports&quot;);
          var content = await response.Content.ReadAsStringAsync();
  
          if (!response.IsSuccessStatusCode)
          {
              throw new ApplicationException(content);
          }
  
          var results = JsonSerializer.Deserialize&lt;List&lt;Reports&gt;&gt;(content, _options);
          return results;
      }
  
  }
  </code></pre>