Repository navigation
Closed
Labels
Description
Using the code defined in the README https://github.com/reactiveui/refit#reducing-header-boilerplate-with-delegatinghandlers-authorization-headers-worked-example, running the app results in an exception:
Unexpected application termination! "The 'InnerHandler' property must be null. 'DelegatingHandler' instances provided to 'HttpMessageHandlerBuilder' must not be reused or cached.\nHandler: 'Easee.Connector.AuthHeaderHandler'"
System.InvalidOperationException: The 'InnerHandler' property must be null. 'DelegatingHandler' instances provided to 'HttpMessageHandlerBuilder' must not be reused or cached.
Handler: 'Easee.Connector.AuthHeaderHandler'
at HttpMessageHandler Microsoft.Extensions.Http.HttpMessageHandlerBuilder.CreateHandlerPipeline(HttpMessageHandler primaryHandler, IEnumerable<DelegatingHandler> additionalHandlers)
at HttpMessageHandler Microsoft.Extensions.Http.DefaultHttpMessageHandlerBuilder.Build()
at ActiveHandlerTrackingEntry Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateHandlerEntry(string name)
at ActiveHandlerTrackingEntry Microsoft.Extensions.Http.DefaultHttpClientFactory+<>c__DisplayClass14_0.<.ctor>b__1(?)+() => { }
at void System.Lazy<T>.ViaFactory(LazyThreadSafetyMode mode)
at void System.Lazy<T>.ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
at T System.Lazy<T>.CreateValue()
at T System.Lazy<T>.get_Value()
at HttpMessageHandler Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateHandler(string name)
at HttpClient Microsoft.Extensions.Http.DefaultHttpClientFactory.CreateClient(string name)
Steps To Reproduce
Expected behavior
My app to run.
I believe you shouldn't set the InnerHandler
Environment
- OS: macOS 12.5
- .NET Core: 6
Reacted by Florian Garcia, Samdanae Imran, ysmoliak, Ronan Burke, Maxime C., Edi Wang, Alex Redding, Laurence0x03, Ben Brandt, Matthias Hehle and 3 more
Activity
MarkEnverus commentedon Oct 10, 2022
This still seems to be an issue - when using RestService.For - the code works, but when using Dependency Injection (HttpClientFactory) the code fails.
I was able to work around it using => AuthorizationHeaderValueGetter.
Ninja2 commentedon Oct 31, 2022
As @jchannon said, the inner handler should not be set when using from DI or it will fail when building the handlers pipeline
MarkEnverus commentedon Oct 31, 2022
@Ninja2 should we update the docs to reflect this? It's confusing and then you need separate setups for either RestService.For and DI?
noontz commentedon Apr 6, 2023
I can confirm this issue when implementing on Azure Functions.
In case others end here as me ( and the issue isn't closed ;) )
My current workaround is to add a flag in the DelegatingHandler constructor e.g.
Hence for DI (Azure Functions):
For RestService.For (Testing):
Document InnerHandler null requirement for DI
fix: Document InnerHandler null requirement for DI (#1569)
salghazaly commentedon Nov 23, 2023
I m facing the same issue in a MAUI Blazor App .Net 7.0
in my app there are two messages handlers one for SSL Pinning as follow
and a DelegatingHandler message handler for httpclient request as follow
I m injecting httpsclient as follow
Really the app is working fine but sometimes this issue appears suddenly even sometimes when the app is idle for a while I get this error as follow
blazor.webview.js:1 The 'InnerHandler' property must be null. 'DelegatingHandler' instances provided to 'HttpMessageHandlerBuilder' must not be reused or cached.
Handler: 'CustomHttpRequestHandler '
rsr-maersk commentedon Dec 13, 2023
any status update here?
github-actions commentedon Jul 5, 2024
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.