Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor WASM error: 'window.crypto.randomUUID is not a function'

When I deploy my asp.net Blazor WASM app I get the following error when MSAL tries to authenticate.

window.crypto.randomUUID is not a function

I've seen this article on microsoft's website, not sure if it is related or not, but I wouldn't have expected MS to use it in .NET 7 if it was removed.

I can't work out what to do about this, can anyone help?

What I've tried so far

  1. Putting this into my client csproj file
<ItemGroup>
  <TrimmerRootAssembly Include="Microsoft.Authentication.WebAssembly.Msal" />
</ItemGroup>
  1. Putting this into my client csproj file
<ItemGroup>
  <BlazorLinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>

with this in the xml file

<?xml version="1.0" encoding="utf-8" ?>
<linker>
  <assembly fullname="Microsoft.Authentication.WebAssembly.Msal" />
</linker>
like image 590
Peter Morris Avatar asked Oct 28 '25 04:10

Peter Morris


1 Answers

The problem was that window.crypto.randomUUID only runs when your domain is localhost, or when the request is via HTTPS.

Solution: Instead of http (which seems to be VS default after publishing) use https.

like image 94
Peter Morris Avatar answered Oct 30 '25 18:10

Peter Morris