25

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

oguz ismail
  • 1
  • 16
  • 47
  • 69
aherrick
  • 19,799
  • 33
  • 112
  • 188

3 Answers3

67

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>
Rogn
  • 969
  • 8
  • 5
  • 4
    If you have issues after adding this, try the following: Delete all bin and obj folders from the solution, delete all the files in destination folder on the server before publishing again. – 130nk3r5 Nov 19 '21 at 12:50
  • 3
    The location this is added in the .csproj file does matter. Adding it to the end does not work. Placing it directly after your PackageReference item group seems to work. – ChronoZZ Dec 09 '21 at 13:02
  • Thanks, this was a big help and saved me a lot of angst. I did need to delete the bin/obj folders after initial errors but all is good. – Jim K Jan 19 '22 at 15:18
  • This solved my problem. I didn't see the issue until I setup a GitHub CI/CD action and deployed the application to an Azure App Service. – dahln Feb 17 '22 at 03:07
  • 3
    For anyone getting the "Failed to find a valid digest in the 'integrity' attribute for resource" see @130nk3r5 comment above about deleting bin and obj – Stewart Cunningham Feb 23 '22 at 13:59
  • 1
    This saved me many hours of debugging after updating from 5 to 6, Many Thanks! :) – WouldBeNerd Mar 29 '22 at 02:35
  • After I deleted the binaries in the bin and obj folders this worked. Thanks very much. – Christian Storb Apr 01 '22 at 15:23
  • 3
    This issue is prevalent in Blazor WASM deployed to a Blob Storae static website as well. Same solution of TrimmerRootAssembly works. – avsln May 02 '22 at 01:48
  • Wow just had this issue for days trying to deploy a blazor wasm to azure app service. Thanks for the workaround – MiddleTommy Jun 09 '22 at 23:14
  • Literally spent 2 days looking into why my Blazor web assembly UI wasn't working when deployed to Azure but worked locally - this was the solution. – Rob C Feb 08 '23 at 17:03
1

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.

JonathanK
  • 57
  • 1
  • 5
0

If you publish a project in a docker container, you should add .dockerignore to your solution and make it ignore the bin and obj folders

**/obj/
**/bin/