'Blazor WebAssembly Application fails to load due to integrity errors

We have developed a Blazor WebAssembly Application that has already gone into productive usage for a certain group of customers.

The Application works well in all Browsers with Standard Security settings. However, this morning I got a call from one of the customers, where the Application did not load at all in their Chrome Browser.

I saw the following Errors in the console:

  • Unknown error occurred while trying to verify integrity.
  • Failed to load resource: the server responded with a status of 403 (forbidden)
  • Failed to find a valid digest in the 'integrity' attribute for ressource '<somepath.dll>' with SHA-256 integrity <sha56>. the resource has been blocked

Now my question is, what could cause this? Is this a Browser Security setting, or another security setting e.g on server, in code etc.? How can I fix this?

Here's a picture of the errors mentioned above

Console Errors Blazor Chrome



Solution 1:[1]

The most likely reason why this is happening, is that some Antiviruses block the execution of downloaded .dll files. That's why it is working in some networks, but doesn't in some others.

What you can do, and what is also suggested as a Workaround by microsoft, is to rename all .dll to .bin - and also change the config json. it worked in my case.

I use the following PowerShell function for that:

Function Hide-BlazorDLL {

    Param(
        [string]$Path = (Get-Location).Path
    )

    <#
        According to the following Links:
        https://github.com/dotnet/aspnetcore/issues/19552
        https://github.com/dotnet/aspnetcore/issues/5477#issuecomment-599148931
        https://github.com/dotnet/aspnetcore/issues/21489
        https://gist.github.com/Swimburger/774ca2b63bad4a16eb2fa23b47297e71 
    #>

    # Test if path is correct and accessible
    $WorkingDir = Join-Path $Path "_framework"
    if (!(Test-Path $WorkingDir)) { Throw "Wrong path $Path. current location must be wwwroot folder of published application." }

    # Get All Items
    $AllItems = Get-ChildItem $WorkingDir -Recurse
    $DLLs = $AllItems | Where-Object { $_.Name -like '*.dll*' }
    $BINs = $AllItems | Where-Object { $_.Name -like '*.bin*' }

    # End script if no .dll are found
    if ($DLLs) { 

        # Delete all current .bin files
        if ($BINs) {
            Remove-item $BINs.FullName -Force
        }
    
        # Change .dll to .bin on files and config
        $DLLs | Rename-item -NewName { $_.Name -replace ".dll\b",".bin" }
        ((Get-Content "$WorkingDir\blazor.boot.json" -Raw) -replace '.dll"','.bin"') | Set-Content "$WorkingDir\blazor.boot.json"
    
        # Delete Compressed Blazor files
        if (Test-Path "$WorkingDir\blazor.boot.json.gz") {
            Remove-Item "$WorkingDir\blazor.boot.json.gz"
        }
        if (Test-Path "$WorkingDir\blazor.boot.json.br") {
            Remove-Item "$WorkingDir\blazor.boot.json.br"
        }
    
        # Do the same for ServiceWorker, if it exists
        $ServiceWorker = Get-Item "$Path\service-worker-assets.js" -ErrorAction SilentlyContinue
        if ($ServiceWorker) {
            ((Get-Content $ServiceWorker.FullName -Raw) -replace '.dll"','.bin"') | Set-Content $ServiceWorker.FullName
            Remove-Item ($ServiceWorker.FullName + ".gz")
            Remove-Item ($ServiceWorker.FullName + ".br")
        }
    }
    else {
        Write-Host "There are no .dll Files to rename to .bin" 
    }
}

Basically you need to navigate to the wwwroot folder of your published application and run the function there. e.g:

PS D:\inetpub\wwwroot\<appname>\wwwroot> Hide-BlazorDLL

Solution 2:[2]

Solution for me was to delete the obj and the bin folder in both the client and the server project folder

Solution 3:[3]

This error for some reason kept happening for me when I tested my application in an anonymous browser window (Google Chrome).

Try using a normal browser window if you're getting integrity errors.

Also, if you're using Cloudflare CDN don't forget to "Purge Everything" in the cache.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Sander
Solution 3 Michal Zatloukal