35

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Ibanez1408
  • 4,550
  • 10
  • 59
  • 110
  • That code by itself is OK, you are probaly using the wrong packages. Make sure you are up to date to the 3.0 released version. For an existing project, follow the update guidelines. – H H Oct 11 '19 at 08:25
  • @HenkHolterman Could you please point out what package to install for that error? – Ibanez1408 Oct 11 '19 at 08:58
  • But I now see the client-side tag. The App.razor you posted is for server-side. – H H Oct 11 '19 at 09:02
  • but it is in the client side. Ever since last update, I couldn't run this anymore. on my last work, before this last update, i was able to make this run without issues. – Ibanez1408 Oct 11 '19 at 09:07
  • The latest of what package Sir? – Ibanez1408 Oct 11 '19 at 09:08
  • post the contents of your csproj. More specifically, the `ItemGroup` containing all the `` – Tewr Oct 11 '19 at 11:56
  • Microsoft's dotnet repo has a related issue: https://github.com/dotnet/razor-tooling/issues/4590 – mfluehr Dec 22 '21 at 14:52

7 Answers7

33

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.

pRob3
  • 371
  • 4
  • 7
  • 1
    This one worked for me. I was using LTS versions for packages so updates SHOULD not be needed! – David Jones Oct 15 '20 at 11:53
  • I thought this solutions originally did not work, but it can apparently take a few minutes for VS to re-index the project dependencies and make the squiggles go away in some cases. This appears to have fixed my issue! Thank you! – Jerrill Oct 03 '22 at 15:26
20

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

Konstantin Salavatov
  • 4,370
  • 2
  • 25
  • 24
  • Don't forget to also install the correct NuGet pages for this to work. – Justin Feb 16 '21 at 13:06
  • 3
    They were already present and still have the same issue. Deleting the .vs folder works for me. – d.i.joe Dec 07 '21 at 07:31
  • 1
    Had this same issue for the new QuickGrid. I'm a very experienced developer, but the QuickGrid install guide didn't tell me I needed to do this so I didn't. And here I am :-) Just needed to add `@using Microsoft.AspNetCore.Components.QuickGrid` to _Imports.razor – Simon_Weaver May 29 '23 at 20:12
4
  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

ahmetsse
  • 111
  • 5
  • I've had to do this twice now and twice this has helped me because it reminded me to check for NuGet updates, which fixed the problem. – Tod Sep 23 '20 at 13:24
3

For .NET 6

  • Make sure Microsoft.AspNetCore.Components.Authorization NuGet package is installed
  • Add @using Microsoft.AspNetCore.Components.Authorization to _Imports.razor file
Fabio
  • 31,528
  • 4
  • 33
  • 72
3

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

enter image description here

Abhay Desai
  • 143
  • 1
  • 8
1

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

Alex
  • 1,297
  • 1
  • 16
  • 12
  • 2
    I see similar issue with VS2022. Blazor intellisense is pretty terrible. The app compiles and runs flawlessly, but I consistently see warnings and ugly squiggly lines in my code. – Jason D Oct 06 '22 at 10:27
1

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.

ouflak
  • 2,458
  • 10
  • 44
  • 49
Shakil Ahmed
  • 107
  • 1
  • 7
  • This is ultimately the one I have seen so you always have to restart your IDE to fix it. – mw509 Feb 22 '23 at 11:25