Loading ...

Unable to debug Blazor app from Visual Studio | CodeAsp.Net

Unable to debug Blazor app from Visual Studio

Unable to debug Blazor app from Visual Studio

 /5
0 (0votes)

While trying the official example of Counter page for Blazor application I was getting the following message while debugging the application:

A debugger operation is taking a long time to complete. Click "Cancel" to stop waiting and terminate the process.

The solution was to go to Program.cs

and replacing the following line:

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) })

with

builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

 

Here is what the final Program.cs looked like:

 

    public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            builder.RootComponents.Add<App>("#app");

            //builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
            builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

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

 

Comments (no comments yet)

Top Posts