dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.98k stars 4.66k forks source link

Misspelling in a System.InvalidOperation Message #105801

Closed cdomino closed 1 month ago

cdomino commented 1 month ago

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 via AddMsalAuthentication, AddAccountClaimsPrincipalFactory<AccountClaimsPrincipalFactory<RemoteUserAccount>>, and AddHttpMessageHandler<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 the InvalidOperationException; after noticing this misspelling, I remembered why this is a bad idea. 😄

Thanks so much!

stephentoub commented 1 month 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.

cdomino commented 1 month ago

Thanks for the prompt response @stephentoub - I'll dig and see what I can find!

cdomino commented 1 month ago

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!

vcsjones commented 1 month ago

I searched the entirety of GitHub for this exception message, and there was exactly one result for a line in one of your repositories:

https://github.com/cdomino/LinesOfCode-WebWorkers/blob/9a46d4cb63ccd3f8cb72c7f8db7ab0f2a60c3ae1/Managers/DependencyManager.cs#L97

cdomino commented 1 month ago

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!