Can't hit breakpoint in program.main Blazor Client wasm
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.
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}"
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();
}
}
Update: The documentation that describes this
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.
Note, I couldn't get Debugger.IsAttached
or Debugger.Break()
to work, so you have to set a breakpoint in the editor.
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();
}
}