首页 > 解决方案 > 在 Visual Studio 2019 中调试 Blazor WebAssembly 代码隐藏文件时无法检查组件属性

问题描述

我最近将我的 Blazor Server 应用程序转换为 Blazor WebAssembly,并注意到 Visual Studio 2019 中的调试不再正常工作。

我仍然可以单步调试我的组件并检查局部变量,但我无法再以任何方式检查我的组件的属性。Visual Studio 告诉我“无法评估”。

我的代码是使用代码隐藏方法构建的。我发现如果我将代码文件直接合并到组件中的 @code 块中,那么问题就会消失。但我不想这样做,因为这似乎是倒退了一步。

示例 1. 直接嵌入到组件中的代码...检查属性工作正常

反剃刀

@page "/Counter"
<DebugChild Max="20"></DebugChild>

DebugChild.razor

<h2>DebugChild</h2>
@code
{
    [Parameter]
    public int Max { get; set; }

    protected override void OnInitialized()
    {
        var x = Max; //I can inspect Max here
    }
}

示例 2. 代码拆分为代码隐藏文件...检查属性不起作用

反剃刀

@page "/Counter"
<DebugChild Max="20"></DebugChild>

DebugChild.razor

@inherits BlazorWASMHosted.Client.Components.DebugChild
<h2>DebugChild</h2>

DebugChild.razor.cs

Using Microsoft.AspNetCore.Components;
namespace BlazorWASMHosted.Client.Components
{
   public class DebugChild : ComponentBase
    {
        [Parameter]
        public int Max { get; set; }

        protected override void OnInitialized()
        {
            var x = Max;  //I CANNOT inspect Max here
        }
    }
}

我尝试使用部分类而不是 interitance 进行代码隐藏,但也没有运气。有没有人有什么建议?

标签: c#debuggingblazorblazor-webassembly

解决方案


推荐阅读