无法在program.main Blazor Client wasm中达到断点 [英] Can't hit breakpoint in program.main Blazor Client wasm

查看:73
本文介绍了无法在program.main Blazor Client wasm中达到断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个基本的Blazor应用程序,我正在尝试调试应用程序的main/start方法.主要是检查我要注入的对象,主要是从appsettings.json获取配置.

Create a basic Blazor App, I'm trying to debug the main/start method of my app. Mainly to check the objects I'm injecting and primarily getting the configurations from appsettings.json.

我还在lauchSettings.json中添加了用于浏览器调试的json设置,但没有成功.

I've also added the in lauchSettings.json the json setting for browser debug but no success.

"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"

我已经在Google上进行了检查,但是与Program.Main()断点有关的解决方案并不多.有什么建议吗?

I've checked on google but not many solution in relation to the Program.Main() breakpoints. Any suggestions?

public class Program
{
    public static async Task Main(string[] args)
    {

        var builder = WebAssemblyHostBuilder.CreateDefault(args);



        builder.RootComponents.Add<App>("#app");
        builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri("https://localhost:5001/") });
        builder.Services.AddScoped<DashboardDataService>();
        builder.Services.AddScoped<TrTradingSignalBotApiService>();
        builder.Services.AddTelerikBlazor();

        await builder.Build().RunAsync();
    }
}

推荐答案

好吧,这很丑,但是想必您只想一次性使用它,所以请等待几秒钟-在我的桌面上等待2秒钟够了-它给了调试器附加的时间.找到适合自己的延迟后,它就会起作用.

Ok, this is ugly, but presumably you only want it as a one-off, so just wait a few seconds - for me on my desktop, 2 seconds is enough - it gives the debugger time to attach. Once you find the delay that works for you, it works.

注意,我无法使 Debugger.IsAttached Debugger.Break()正常工作,因此您必须在编辑器中设置断点.

Note, I couldn't get Debugger.IsAttached or Debugger.Break() to work, so you have to set a breakpoint in the editor.

#if DEBUG ...#endif 中包裹延迟,以确保您没有放开它.

Wrap the delay in #if DEBUG...#endif to make sure you don't release with that in place.

public class Program
{
    public static async Task Main(string[] args)
    {
#if DEBUG        
        await Task.Delay(2000);
#endif
        var builder = WebAssemblyHostBuilder.CreateDefault(args);

        builder.RootComponents.Add<App>("#app");
        builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri("https://localhost:5001/") });
        builder.Services.AddScoped<DashboardDataService>();
        builder.Services.AddScoped<TrTradingSignalBotApiService>();
        builder.Services.AddTelerikBlazor();

        await builder.Build().RunAsync();
    }
}

这篇关于无法在program.main Blazor Client wasm中达到断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆