aspnetcore: net7 Blazor WASM AAD authentication ends with There was an error trying to log you in: '"undefined" is not valid JSON'

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Sample project: https://github.com/havit/Bonusario

When upgraded from net6 to net7 the application started to fail with

` There was an error trying to log you in: '"undefined" is not valid JSON'

right after logging in to Azure AD (end of auth workflow).

Applies only for published version, does not occur in development.

After several attempts I found that disabling assembly trimming for Microsoft.AspNetCore.Components.WebAssembly.Authentication resolves the issue.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

Workaround

Add

<assembly fullname="Microsoft.AspNetCore.Components.WebAssembly.Authentication" preserve="all" />

to your TrimmerRootDescriptor.xml.

See https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 30 (6 by maintainers)

Most upvoted comments

So just to get this straight:

Prior to .NET 7, we needed:

<ItemGroup>
    <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
</ItemGroup>

Then .NET 7 fixed this, but broke something else, and instead of the above, we now need:

<ItemGroup>
    <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
</ItemGroup>

And when changing these entries, we need to make sure to clean obj/bin folders or we get an unclean build with integrity errors.

@TanayParikh This seems different from the trimming error we saw before. The same issue was described in this comment. I’d say this is a real thing and possibly a servicing candidate.

We’re having this problem too. For us, everything works fine on our laptops, but fails as soon as we deploy it to Azure. We’re serving the app from a CDN.

When we added this to our csproj, the problem goes away:

<ItemGroup>
    <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
</ItemGroup>

Hm, interesting. It might be. The good news is that you don’t need the Microsoft.Authentication.WebAssembly.Msal included anymore. That issue is actually fixed in the net7 release. (See #33312)

Ahh sweet thanks for the tip! I will remove that now and run some tests. Actually it seems that the publishing time for me about doubled when upgrading to .NET 7 in general. Notwithstanding the TrimmerRootAssembly option.

If you don’t need the TrimmerRootDescriptor XML for anything else already, a faster workaround is to just add

<ItemGroup>
    <TrimmerRootAssembly Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" />
</ItemGroup>

in your csproj file