Share via

I'm getting the An Unhandled Exception error message for the umpteenth time

Falanga, Rod, DOH 940 Reputation points
2026-03-17T20:41:51.76+00:00

I've been working on a Blazor app, currently written in .NET 9, for a year. Over that period of time everyone on the team has experience that, "An unhandled exception" error message in a yellow background at the bottom of the page. Also, over that time I have searched for what causes that error message to appear many times. I've come across lots of pages and websites giving some help. Some have helped, but then when it comes back again, the recommendation no longer works. I am in that situation now. We've deployed the app to an internal server for testing. I am getting that error again. I asked a colleague to test it, and he isn't experiencing any problems; everything works fine.

So, I conclude that it is either something on my machine, or my account. I've rebooted my machine, which is one of the things suggested to do in the past and has often worked, but today, it doesn't help. I have also shut down my machine for 5 minutes, but that hasn't helped either. So, what can I do to make this work?

Developer technologies | .NET | Blazor

Answer accepted by question author
  1. Jack Dang (WICLOUD CORPORATION) 16,515 Reputation points Microsoft External Staff Moderator
    2026-03-18T04:40:24.08+00:00

    Hi @Falanga, Rod, DOH ,

    Thanks for coming back and sharing your solution.

    It’s a great example of how environment differences (Kestrel vs IIS) can lead to subtle issues.

    When you run your app using Kestrel (the default HTTPS profile in Visual Studio), you’re using a lightweight, cross-platform web server. However, features like Windows Authentication are not handled the same way unless Kestrel is hosted behind IIS.

    On the other hand, when you switch to IIS Express, your app runs in an environment much closer to full IIS, which natively supports Windows Authentication and manages the request pipeline differently.

    Microsoft docs explain these differences here:

    A couple of key takeaways from those:

    • Kestrel by itself doesn’t provide the same level of integration for Windows Authentication
    • IIS/IIS Express handles authentication and request processing more tightly with Windows
    • Running behind IIS ensures the app gets a consistent user identity and request context

    So, in your case, when running under Kestrel, parts of your app that depend on Windows Authentication (like cookies or API calls tied to user identity) likely weren’t behaving as expected, which surfaced as those “unhandled exception” errors.

    Switching to IIS Express aligned your local environment with how the app is actually hosted, which is why the issue went away.

    Hope my explanation was helpful and I would greatly appreciate it if you could follow the instructions here so others with the same problem come across this answer can benefit as well.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-17T20:42:13.5533333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The yellow bar with “An unhandled exception occurred” is Blazor’s built‑in UI that appears whenever an exception escapes your component code or the Blazor framework on your circuit. It isn’t a special “environment” or “machine” error: it is a symptom that some code path in your app is throwing and not handling an exception.

    Key points from the platform behavior:

    1. What that yellow bar means
    • Blazor renders a div with id="blazor-error-ui" when an unhandled exception occurs.
    • In development, it tells the developer to look in the browser console for details.
    • In production, it just shows a generic message and suggests reloading.
    • The UI is part of the Blazor project template and is normally hidden via CSS until an error occurs.
    1. Why it can affect one user and not another Blazor treats most unhandled exceptions as fatal to the circuit (the per‑browser‑tab connection and state on the server):
    • Each browser tab/user has its own circuit.
    • An unhandled exception kills only that circuit; other users/tabs continue normally.
    • If only one account or machine sees the yellow bar, that user is hitting a code path (data, navigation, parameters, permissions, etc.) that throws, while others are not.
    1. Where to look for the actual cause Unhandled exceptions can occur in several places:
    • Component instantiation (constructors or injected services).
    • Lifecycle methods (OnInitialized[Async], OnParametersSet[Async], etc.).
    • Rendering logic (e.g., dereferencing null in markup like @someObject.Property).
    • Event handlers (@onclick, @onchange, @bind, etc.).
    • Component disposal (IDisposable.Dispose).
    • JavaScript interop calls (IJSRuntime.InvokeAsync).
    • Prerendering (exceptions during initial render on the server).

    Any unhandled exception in those areas is logged and, for server‑side circuits, is fatal to that circuit.

    1. How to actually diagnose it on the problem machine Since the yellow bar is only a generic indicator, the next steps are:
    • Check the browser console on the affected machine
      • In development, Blazor sends full exception details to the browser console. The yellow bar explicitly tells to look there.
      • Compare what appears in the console on the failing machine vs. the working one.
    • Check server logs
      • Blazor logs unhandled exceptions to ILogger providers configured in the app.
      • Use a persistent logging provider or APM (for example, Azure Application Insights) so that exceptions from specific users/machines can be inspected.
    1. Make the app resilient so the yellow bar appears less often To prevent unhandled exceptions from killing circuits:
    • Guard rendering logic against null
      • Example pattern:
            @if (person.Address != null)
            {
                <div>@person.Address.Line1</div>
                <div>@person.Address.Line2</div>
                <div>@person.Address.City</div>
                <div>@person.Address.Country</div>
            }
        
    • Add try-catch with logging around risky operations
      • In lifecycle methods (e.g., data loading in OnParametersSetAsync).
      • In event handlers (e.g., database calls, HTTP calls, JS interop).
      • In Dispose if disposal logic can fail.
    • Use environment‑appropriate error messages
      • For Blazor Web Apps, inject IHostEnvironment into MainLayout and show different text in production vs. development, while still logging full details.
    1. Environment and detailed errors
    • For server‑side rendering, RazorComponentsServiceOptions.DetailedErrors controls whether detailed error information is produced.
    • It should only be enabled in the Development environment, typically:
        builder.Services.AddRazorComponents(options => 
            options.DetailedErrors = builder.Environment.IsDevelopment());
      
    1. Why rebooting sometimes “fixes” it Rebooting or restarting the browser creates a new circuit and clears transient state, so if the exception was tied to a particular corrupted state or sequence of actions, it may not reoccur immediately. However, the underlying bug remains and will reappear when the same code path is hit again.

    To move forward on the specific machine/account:

    • Reproduce the issue and capture the browser console output and corresponding server logs.
    • Identify which of the known exception locations (lifecycle, rendering, event handler, JS interop, etc.) is throwing.
    • Add appropriate try-catch, null checks, and logging so that the app handles the error gracefully instead of letting it bubble up and terminate the circuit.

    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.