You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue when my Typed HttpClient was using a generic type. In my example .AddHttpClient<GenericClient<MyName>> produced "GenericClient`1" in the IContextualHttpClientFactory.CreateClient<TClient>(string handlerContext)) method
This resolved the FullName with the generic type included.
UPDATE: This solution did not work, the TClient needs to resemble the exact name that the internal AddHttpClient would create, being GenericClient<MyName>.
What did end up working was to replicate the TypeNameHelper.GetTypeDisplayName() code referenced above. Working Example.
I have a pending branch and PR to address this issue along with additions to properly handle typed clients with interfaces and some other small quality of life updates.
3.0.0-rc is available here and as a pre-release package on Nuget. It has a major version increment due to some small changes on interfaces.
The issue you reported is addressed by a new wrapper type called TypedClientSignature that uses an internal implementation of TypeNameHelper and has implicit conversion to and from a string to maintain existing comparison logic.
In addition to resolving issues with typed clients with a generic parameter, the handler factory logic now supports
client.IsTypedClient<TypedClient>()
in favor of (but optionally in addition to the potentially inaccurate)
client == typeof(TypedClient).Name
Let me know if you have any issues with the RC, will plan to merge this week.
I encountered an issue when my Typed HttpClient was using a generic type. In my example
.AddHttpClient<GenericClient<MyName>>
produced "GenericClient`1" in theIContextualHttpClientFactory.CreateClient<TClient>(string handlerContext))
methodThis caused issues as I was expecting the name to be
GenericClient<MyName>
. It looks like in .NET there is an internal method that resolves the TClient name string. See this code string name = TypeNameHelper.GetTypeDisplayName(typeof(TClient), fullName: false);I resolved the issue by creating my own
IContextualHttpClientFactory
and creating the CreateClient to look like thisThis resolved the FullName with the generic type included.
UPDATE: This solution did not work, the
TClient
needs to resemble the exact name that the internal AddHttpClient would create, beingGenericClient<MyName>
.What did end up working was to replicate the
TypeNameHelper.GetTypeDisplayName()
code referenced above. Working Example.The text was updated successfully, but these errors were encountered: