dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.47k stars 10.03k forks source link

Blazor error after update to .NET 8: Failed to start platform. #50755

Closed PeterDraex closed 1 year ago

PeterDraex commented 1 year ago

I've tried to update my solution to .NET 8 RC.1. I've updated all packages and cleaned all bin and obj folders. Still, I ended up with the following error:

Failed to start platform. Reason: TypeError: Cannot read properties of undefined (reading 'AspNetCore')

This error shows up in the browser console when I start the app and open the Blazor client website. Is this a known issue? How can I go about debugging it?


My solution contains 3 distinct Blazor clients. One client works fine after update, two get this error, so I think this will be a common issue. I don't have an example project I could share publicly, but I thought it's worth creating the issue, so when others fail to update to .NET 8 and face the same issue, they can find it, give it a 👍 or contribute.

akurone commented 1 year ago

hi @PeterDraex, does any of the failing projects serve blazorwasm from an asp.net core backend? currently i am experiencing a similar (may be same) problem (with the mentioned setup). at first sight it seems like the new blazor-unified approach is going to break asp.net-backed wasm solutions. if my setup matches with yours i will try to investigate this and hopefully provide a repro; if not i can proceed with another issue.

PeterDraex commented 1 year ago

Hi @akurone, yes, I'm also using Blazor WebAssembly with ASP.NET Core backend. Thanks for investigating!

sofiageo commented 1 year ago

Maybe it doesn't help your case but .net 8 rc1 is broken. Try with preview7 or daily rc2 builds.

pekspro commented 1 year ago

I'm having a similar issue. Clearing the cache storage seems to fix it:

image

ghost commented 1 year ago

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

PeterDraex commented 1 year ago

I'm having a similar issue. Clearing the cache storage seems to fix it:

image

I've tried to migrate the project again, and it's working okay. I assume it was the cache issue as @pekspro mentioned. I'll close the issue for now. If anybody is having the same problem and clearing the cache storage doesn't fix it, we can reopen.

pekspro commented 1 year ago

I think this issue should be remained open. If an end user run into this, they would probably be stuck.

As an extra protection, I have added a Reload-button on the loading screen. It appears after four seconds, and if the users press that button all caches will be cleared, and the page will be reloaded.

This is my updated load-section:

<div id="app">
    <svg class="loading-progress">
        <circle r="40%" cx="50%" cy="50%" />
        <circle r="40%" cx="50%" cy="50%" />
    </svg>
    <div class="loading-progress-text"></div>
    <div class="loading-reload-text">
        <a href="#" id="reload-link">Reload</a>
    </div>

    <script>
        document.getElementById('reload-link').addEventListener('click', function (event) {
            event.preventDefault();

            caches.keys().then(function (cacheNames) {
                return Promise.all(
                    cacheNames.map(function (cacheName) {
                        return caches.delete(cacheName);
                    })
                );
            }).then(function () {
                window.location.reload(true);
            });
        });
    </script>
</div>

And this is my added CSS:

.loading-reload-text {
    text-align: center;
    opacity: 0;
    animation: loading-reload-fade-in 1s ease-in-out 4s forwards;
}

@keyframes loading-reload-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.loading-reload-text a {
    font-weight: 300;
    font-size: 90%;
}
pekspro commented 1 year ago

I can add that when I switch from .NET 7 to .NET 8, it mostly works fine on my computer, but not every time. On Edge and Chrome on Android I more often get an issue. My error messages from the console (both computer and Android) are:

Error: Failed to start platform. Reason: TypeError: Cannot read properties of undefined (reading 'dotnet.wasm')
    at Vt (blazor.webassembly.js:1:62226)

Uncaught (in promise) TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at blazor.webassembly.js:1:37659
    at blazor.webassembly.js:1:38464
    at Object.start (blazor.webassembly.js:1:46018)
    at Vt (blazor.webassembly.js:1:62202)
akurone commented 1 year ago

for the follow-up about repro: my problem (#50984) was totally different. so, there is a repro but not for this; sorry :)

AbstractionsAs commented 1 year ago

Clearing cache storage does not resolve this problem for me (rc2, webassembly standalone)

sequarell commented 1 year ago

I get the same error with a completely emty, newly created Blazor WASM AzureB2C project. (dotnet new blazorwasm -au IndividualB2C ....)

pekspro commented 1 year ago

@AbstractionsAs, @sequarell, this thread is closed, I doubt anyone is watching :-)

I've created a new thread here: https://github.com/dotnet/aspnetcore/issues/51268

AbstractionsAs commented 1 year ago

@pekspro @sequarell

I was able to resolve this by:

I noticed that the versions in VS didn't match the packagereference versions. NOthing except actually copy-pasting them in and out actually resolved this.

Seems to be some kind of bug in VS preview.

zaneclaes commented 1 year ago

FWIW, the specific error from the OP (reading 'AspNetCore') can happen if you remove the package references to Microsoft.AspNetCore.Components.WebAssembly from the Blazor wasm project.

fgilde commented 11 months ago

Excacly the same issue with the released version from today. Cache storage cleaning doesnt help. The only thing that really helps me was the tip from @AbstractionsAs

Cutting the packagereferences from the .csproj Saving the csproj and waiting for the references to update in VS Pasting the packagereferences back in Clean Rebuild

that works for me

jarlef commented 11 months ago

I assume this has to be due to old assets not being cleaned up in the bin/obj folders. Just delete the bin/obj folders, restore the nuget packages, build and run the blazor application.

sgorozco commented 10 months ago

This also happens if you try to upgrade an old Blazor WebAssembly project that is hosted by an ASP.NET Core app from 7.0 to 8.0. The solution from @AbstractionsAs solves the problem in this scenario too.

CygnusKraft commented 10 months ago

I had changed from 7.0 -> 8.0, updated all packaged to 8.0, still received the error.

@AbstractionsAs solution worked for me as well.

alperenbelgic commented 10 months ago

I am having this error on Edge browser (chrome works fine) , it's built by GitHub actions and deployed to Cloudflare pages. @AbstractionsAs's solution seems like a local environment solution.

update: as mentioned in another ticket, the issue is cache-related. In my case, cloudflare cdn was caching some files. I triggered purge cache and the issue is gone.

jjamid commented 9 months ago

What worked for me was manually deleting the folders under bin\Debug and rebuilding, not deleting the cache. Also it seems that 8.0 now requires a connection to the internet in order to debug aŚ“ it downloads files from https://raw.githubusercontent.com/dotnet/runtime We had to exclude this path on the proxy to be able to develop.

hagaygo commented 8 months ago

Same here.

Upgrading from WASM app from 7 to 8.

App refused to load ("Failed to start platform ..." error on console) Only after performing "clean" the app worked.

zhlavinka-cricut commented 8 months ago

Just upgraded a hosted WASM app (net7 > 8). Did the cut/paste trick and the browser cache clear and everything started working again.

Tomas1802 commented 7 months ago

Had the same problem from .Net 6 to .Net 8 and @AbstractionsAs Solution had worked for me as well.

nammadhu commented 5 months ago

hey guys, be Simple... Just update to .net 8(from 6/7/any) then manage nuget packages and then update all to lastest probably like 8.0.5 within a minute all fixed... enjoy... nothing else required...

image
amguilmet commented 5 months ago

The same thing happens to me with Rider. Just had to delete bin/obj folders and then do a nuget restore making sure all packages were the latest (8.0.6).

nicholasyin commented 3 months ago

What worked for me was manually deleting the folders under bin\Debug and rebuilding, not deleting the cache. Also it seems that 8.0 now requires a connection to the internet in order to debug aŚ“ it downloads files from https://raw.githubusercontent.com/dotnet/runtime We had to exclude this path on the proxy to be able to develop.

Saved my day. Thanks a lot.

ChhaganSinha commented 2 months ago

To resolve this issue go to program.cs of your client project(if you are using ASP.NETCORE Hosted blazor WASM) and replace this builder.Services.AddHttpClient("yourApplicationName.ServerAPI", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))

to

builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

this will resolve the error "Failed to start platform. Reason: TypeError: Cannot read properties of undefined (reading 'AspNetCore')"