Jurioli / Blazor.WebForm.Components

ASP.NET Web Forms System.Web.UI.WebControls Razor Components For Blazor WebAssembly, Blazor Hybrid, Blazor Server.
MIT License
44 stars 9 forks source link

components don't work on .net 8 #7

Closed Riccardo219 closed 8 months ago

Riccardo219 commented 8 months ago

Hi, I created a new Blazor Server project on .NET (8.0.100) and installed the Blazor.WebForm.Components version (2.4.0.1). I added the ScriptManagerCircuitHandler class to the Program.cs. I added some webform components to the Home and when I click on the button nothing happens. An error appears in the Google Console (see figure).

image

Even if I insert a breakpoint in the button click event the application does not stop at the breakpoint.

On .NET 7 it works fine.

Jurioli commented 8 months ago

You can add @rendermode InteractiveServer or edit App.razor <Routes @rendermode="InteractiveServer" /> .

This error is because .net8 prerendering enabled (InteractiveAuto), but we can't run like:

@inject IJSRuntime JsRuntime

@code {
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        await this.JsRuntime.InvokeVoidAsync("alert", "test");
    }
}

An unhandled exception occurred while processing the request. InvalidOperationException: JavaScript interop calls cannot be issued at this time. This is because the component is being statically rendered. When prerendering is enabled, JavaScript interop calls can only be performed during the OnAfterRenderAsync lifecycle method.