question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does it work together with HttpClientFactory

See original GitHub issue

Hi, when I try to add this Handler like this:

services.AddSingleton<TracingHandler>(new TracingHandler(ServiceName));
services.AddHttpClient("MyHttpClient", ConfigureMyHttpClient)
   .AddHttpMessageHandler<TracingHandler>();

I get error:

DelegatingHandler instances provided to HttpMessageHandlerBuilder must not be reused or cached

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

5reactions
wdolekcommented, Nov 13, 2018

@senj I believe you are getting this exception because you registered handler as singleton. So after first usage, inner handler stays set and that’s why you get exception. Try to change your registration to:

services.AddTransient(_ => TracingHandler.WithoutInnerHandler("ServiceName"));
0reactions
venkatr21commented, Nov 8, 2022

@dzejsien I am facing the same issue. .AddHttpMessageHandler(_ => TracingHandler.WithoutInnerHandler(“serviceName”)) did this solve the issue? Were you able to find other alternatives / best practices for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using HttpClientFactory in ASP.NET Core Applications
Not only that HttpClientFactory can create and manage new HttpClient instances but also, it works with underlying handlers.
Read more >
Use the IHttpClientFactory - .NET
HttpClient is used for making HTTP requests and handling HTTP responses from web resources identified by a Uri. The HTTP protocol makes up...
Read more >
Getting started with HttpClientFactory in C# and .NET 5
It provides a central place to name and configure our HttpClients . · Delegates handlers in HttpClient and implements Polly-based middleware to ...
Read more >
Exploring the code behind IHttpClientFactory in depth
In this post I look in depth at the code behind the default implementation of IHttpClientFactory and see how it manages HttpClient handler ......
Read more >
HTTP Requests Using IHttpClientFactory
It provides a single location to configure and interact with a particular httpclient. It works with dependency injection and can be injected ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found