Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor WASM Net 6 Preview 4 Azure AD - There was an error trying to log you in: 'Cannot read property 'toLowerCase' of undefined'

I have a simple Blazor WASM running Net 6 Preview 4 that I setup using this guide:

https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory?view=aspnetcore-6.0

The exact code works perfect with Net 5.0 (using corresponding Net 5.0 assemblies)

However when I upgrade to Net 6 I receive the following Authentication error:

There was an error trying to log you in: 'Cannot read property 'toLowerCase' of undefined'

I can't seem to get anymore detail either. This is published on Azure App Service Self Contained publish.

enter image description here

The code can be found here: https://github.com/aherrick/BlazorWASM.Net6Prev4.AzureAD

like image 791
aherrick Avatar asked Jun 02 '21 12:06

aherrick


2 Answers

A workaround to the issue has been discussed here: https://github.com/dotnet/aspnetcore/issues/33312.

In short the issue is caused by assembly trimming. And the workaround is to exclude Microsoft.Authentication.WebAssembly.Msal from trimming by including this in the client project file:

  <ItemGroup>
    <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
  </ItemGroup>
like image 128
Rogn Avatar answered Nov 17 '22 13:11

Rogn


I had the same issue when trying to sign in. Updating Microsoft.Identity.Web and Microsoft.Identity.Web.UI to latest version(1.22.1) and then deleting the bin and obj folders solved the problem for me.

There was no need to add an ItemGroup with TrimmerRootAssembly.

like image 36
JonathanK Avatar answered Nov 17 '22 13:11

JonathanK