Found markup element with unexpected name 'Cascading AuthenticationState'

Viewed 21764

I am getting this error on my App.razor:

Found markup element with unexpected name 'CascadingAuthenticationState'. If this is intended to be a component, add a @using directive for it namespace

This is the code I am using

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>Sorry, there's nothing at this address.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>

enter image description here

I am using Visual Studio 2019 preview and I can run the application but, why do I have the red line in the Cascading....?

6 Answers

Warning! The .vs folder contains all the data that VS gathered about the projects in your solution, the opened files, debug. You will lose all that!

Close Visual Studios and delete the .vs hidden folder in the root of your solution.

Start up your project and the error's will be gone.

For me adding both references to _Imports.razor worked to solve same issue:

@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization

enter image description here

  1. Right Click Project
  2. Manage Nuget Packages
  3. Select "Microsoft.AspNetCore.Blazor" which you have already installed.
  4. Update with Latest stable version then...
  5. Update Latest preview again.

enter image description here

If I create a razor component as right click -> add new item -> razor component, then everything is ok. But if I copy-paste an existing razor component and do further work on it, then it creates the above stated issue.

For .NET 6

  • Make sure Microsoft.AspNetCore.Components.Authorization NuGet package is installed
  • Add @using Microsoft.AspNetCore.Components.Authorization to _Imports.razor file
Related