Ibanez1408
Ibanez1408

Reputation: 5078

Found markup element with unexpected name 'Cascading AuthenticationState'

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....?

Upvotes: 50

Views: 44924

Answers (11)

Petr Tripolsky
Petr Tripolsky

Reputation: 1613

I have removed the .vs rubbish folder. After that there is nothing I can do to make the C# extension in VS Code to work again. Looks like the only way to solve that problem is to open the project with full Visual Studio again

Upvotes: 0

dns_nx
dns_nx

Reputation: 3943

I had a similar issue. I found these entries about my "problem" component in my .csproj file. After deleting them (VS closed) and re-open the solution, the error has been gone.

enter image description here

Upvotes: 1

devbf
devbf

Reputation: 571

The solution which works for me is the following:

  1. Rebuild Solution
  2. Clean Solution
  3. Close VS
  4. Delete all bin/obj folders in the source
  5. Open solution in VS
  6. Rebuild Solution
  7. Close and reopen the file inside of VS where the element is used (not always necessary)
  8. Success, markdown element is found
  9. Sometimes you have to do this procedure multiple times

Upvotes: 8

kpfishon
kpfishon

Reputation: 93

I had this issue with a MudBlazor component, in fact it did not see any MudBlazor component when you typed [Mud into the .razor file in the editor.

As far as I can tell, I was trying to use MudBlazor with .Net 8 and the latest version of MudBlazor has dependency listings for .Net 6 and .Net 7 but nothing listed for .Net 8

After downgrading my Target Framework to .Net 7 the MudBlazor components came back to life, strangely after switching back to .Net 8 they were still there.

Upvotes: 0

Abhay Desai
Abhay Desai

Reputation: 253

This issue went away for me after updating "Build Action" from "None" to "Content" for newly added razor component.

enter image description here

Upvotes: 11

Fabio
Fabio

Reputation: 32455

For .NET 6

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

Upvotes: 3

Shakil Ahmed
Shakil Ahmed

Reputation: 193

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.

Upvotes: 2

Alex
Alex

Reputation: 1295

Looks like it's an IntelliSense issue of the VisualStudio, see: https://developercommunity.visualstudio.com/content/problem/770539/visual-studio-lost-intellisense-for-blazor-compone.html

Upvotes: 1

pRob3
pRob3

Reputation: 666

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.

Upvotes: 61

ahmetsse
ahmetsse

Reputation: 111

  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

Upvotes: 4

Konstantin Salavatov
Konstantin Salavatov

Reputation: 4540

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

Upvotes: 22

Related Questions