Popular blog tags

I'm getting this message in the console when running a server-side Blazor app:

Error: There was an unhandled exception on the current circuit, so this circuit will be terminated. For more details turn on detailed exceptions in 'CircuitOptions.DetailedErrors'

This article will allow you to see the errors in the browser console with ASP.NET Core Blazor 3.x(Server-side).

 

Blazor error handling documentation

https://docs.microsoft.com/en-us/aspnet/core/blazor/handle-errors?view=aspnetcore-3.0

 

1.How to Turn on Detailed Exceptions in CircuitOptions.DetailedErrors with Blazor

You will getting this message in the browser console when running a server-side Blazor app:

Error: There was an unhandled exception on the current circuit, so this circuit will be terminated. For more details turn on detailed exceptions in 'CircuitOptions.DetailedErrors'

In your Startup.cs file you'll need to add an IWebHostEnvironment property to the Startup class. You'll also need to adjust the constructor to accept one.

//Startup.cs
public class Startup
{
  private readonly IWebHostEnvironment _env;

  public Startup(IConfiguration configuration, IWebHostEnvironment env)
  {
      Configuration = configuration;
      _env = env;
  }
 
}

 

Next add the Circuit Options to the ConfigureServices method that already exists.This change will allow you to see the errors in the browser console.

//Startup.cs

public void ConfigureServices(IServiceCollection services)
{
  services.AddRazorPages();
   services.AddServerSideBlazor()
                .AddCircuitOptions(options =>
                {
                    

                    if (_env.IsDevelopment()) //only add details when debugging
                    {
                        options.DetailedErrors = true;
                    }
                });
}

Now the console in your web browser should give you a better error message!

[2019-12-14T15:51:13.199Z] Error: System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at System.Net.Http.HttpClient.GetStringAsyncCore(Task`1 getTask)
   at Microsoft.AspNetCore.Components.HttpClientJsonExtensions.GetJsonAsync[T](HttpClient httpClient, String requestUri)
   at Stockso.BlazorServer.Pages.WebAPI.v1.StockDataPhysicalDiskPanKouAggregateAuctionSearch.OnInitializedAsync() in x\src\BlazorServer\Stockso.BlazorServer\Pages\WebAPI\v1\StockDataPhysicalDiskPanKouAggregateAuctionSearch.razor:line 172
   at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

 

1.How to Turn on Detailed Exceptions in CircuitOptions.DetailedErrors with Blazor

https://mattferderer.com/detailed-exceptions-circuitoptions-blazor