Closed cdomino closed 3 months ago
System.InvalidOperationException: Cannot create an authenticated http cilent because a token was not found. <- Notice "client" is misspelled.
Thanks, but I don't see this text anywhere in dotnet/runtime, dotnet/aspnetcore, or dotnet/extensions. A search of both github and grep.app also turns up nothing. We'd really need a stack trace for this to be actionable.
Thanks for the prompt response @stephentoub - I'll dig and see what I can find!
Hey @stephentoub - best I could do was track it down to IHttpClientFactory.CreateClient(string name). My startup DI config code uses AddHttpClient)) with a name and a delegate that simply sets the BaseAddress
of the HttpClient
objects it will be generating to an absolute URL. Finally, I call .AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>
on the resulting IHttpClientBuilder
to make the MSAL auth magic work.
If this isn't enough to find the typo (or confirm I'm totally looking in the wrong place) then I'll have to add some more logging to my app (since we can't debug Blazor not running on the main UI thread) to acquire a stack trace proper.
I also made sure I had the latest of everything from Nuget, and even Binged around "cilent" but couldn't find anything.
Thanks again!
I searched the entirety of GitHub for this exception message, and there was exactly one result for a line in one of your repositories:
Wulp that's embarrassing for me @vcsjones; I must have already fixed that in my branch and is why I couldn't find it. 😢 Sorry for the noise @stephentoub - this can be closed! Much appreciated gents!
Hello!
I'm using .NET 8 / Blazor WASM / Azure B2C for an app, and noticed a misspelling in an exception message. I built my own multi-threaded client "job system" using web workers, and this occurred when working on an auth token refresh bug.
System.InvalidOperationException: Cannot create an authenticated http cilent because a token was not found. <- Notice "client" is misspelled.
Since this is Blazor C# running on a different browser thread in an IL-generated method, I don't have a proper stack trace to help pinpoint the actual offending code containing the misspelling. However, it is something behind
IHttpClientFactory
(using standard .NET Core dependency injection + MSAL authentication configured viaAddMsalAuthentication
,AddAccountClaimsPrincipalFactory<AccountClaimsPrincipalFactory<RemoteUserAccount>>
, andAddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>
).Considering both that this throws a "generic" exception rather than something more specific around authentication / token expiration and that I'm in a super dynamic context, I thought about going to the dark side and performing logic based on the
Message
string property of theInvalidOperationException
; after noticing this misspelling, I remembered why this is a bad idea. 😄Thanks so much!