23

我在 App.razor 上收到此错误:

发现具有意外名称“CascadingAuthenticationState”的标记元素。如果这是一个组件,请为其命名空间添加一个 @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>

在此处输入图像描述

我正在使用 Visual Studio 2019 预览版,我可以运行应用程序,但是为什么我在 Cascading 中有红线......?

4

5 回答 5

21

警告! .vs 文件夹包含 VS 收集的关于解决方案中的项目、打开的文件、调试的所有数据。你将失去这一切!

关闭 Visual Studios 并删除解决方案根目录中的 .vs 隐藏文件夹。

启动您的项目,错误将消失。

于 2020-09-11T13:58:56.260 回答
18

对我来说,将两个引用都添加到 _Imports.razor 可以解决相同的问题:

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

在此处输入图像描述

于 2019-10-21T16:19:56.677 回答
4
  1. 右键项目
  2. 管理 Nuget 包
  3. 选择已安装的“Microsoft.AspNetCore.Blazor”。
  4. 然后用最新的稳定版本更新...
  5. 再次更新最新预览。

在此处输入图像描述

于 2020-01-05T21:34:39.307 回答
0

如果我创建一个剃须刀组件作为右键单击 -> 添加新项目 -> 剃须刀组件,那么一切正常。但是,如果我复制粘贴现有剃须刀组件并对其进行进一步处理,则会产生上述问题。

于 2022-03-02T15:27:15.553 回答
0

看起来这是 VisualStudio 的 IntelliSense 问题,请参阅:https ://developercommunity.visualstudio.com/content/problem/770539/visual-studio-lost-intellisense-for-blazor-compone.html

于 2020-11-03T20:17:07.547 回答