Aspnetcore: Unhandled exception in circuit after migrating to 3.0 preview 9

Created on 6 Sep 2019  路  2Comments  路  Source: dotnet/aspnetcore

After migrating to Asp.net core 3.0 preview 9 I started getting this exception when starting my Blazor server app:

16:26:57 ERR] Unhandled exception in circuit 'ntIvJ1Q9N86qaaRbnuCYqrSio__1WUzSsTQEcDUJw2E'.
System.AggregateException: One or more errors occurred. (InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@onclick' is not a valid attribute name.)
 ---> System.InvalidOperationException: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@onclick' is not a valid attribute name.
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
   --- End of inner exception stack trace ---

I could finally find out that it works again if I remove the second @onclick attribute from the NavMenu.razor.

Broken version:

<div class="top-row pl-4 navbar navbar-dark">
    <a class="navbar-brand" href="">TestApp</a>
    <button class="navbar-toggler" @onclick="ToggleNavMenu">
        <span class="navbar-toggler-icon"></span>
    </button>
</div>

<div class="@NavMenuCssClass" @onclick="ToggleNavMenu">

Working version:

<div class="top-row pl-4 navbar navbar-dark">
    <a class="navbar-brand" href="">TestApp</a>
    <button class="navbar-toggler" @onclick="ToggleNavMenu">
        <span class="navbar-toggler-icon"></span>
    </button>
</div>

<div class="@NavMenuCssClass">

What's strange is that if I create a new app with dotnet new blazorserver, the template contains the second @onclick attribute and doesn't throw the exception!

In my app I'm importing some packages (e.g.: Blazored.Modal).

Can someone explain the reason for this weird behavior?

area-blazor question

Most helpful comment

Thanks for contacting us, @fleed .
Please refer to the release notes in here showing you the migration steps to Preview9, which includes multiple preview breaking changes.
In this particular case, you're missing a using for Microsoft.AspNetCore.Components.Web: https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-9/#blazor-web-attributes-moved

All 2 comments

Thanks for contacting us, @fleed .
Please refer to the release notes in here showing you the migration steps to Preview9, which includes multiple preview breaking changes.
In this particular case, you're missing a using for Microsoft.AspNetCore.Components.Web: https://devblogs.microsoft.com/aspnet/asp-net-core-and-blazor-updates-in-net-core-3-0-preview-9/#blazor-web-attributes-moved

A bit of help for others which have done the upgrade like @mkArtakMSFT has suggested but still finding the problem.

I had a .razor component in a shared assembly.

The shared assembly compiled fine, but as there is no _Imports.razor I had to manually add the @using Microsoft.AspNetCore.Components.Web to the razor component in the shared library.

Was this page helpful?
0 / 5 - 0 ratings