When injecting a component with a service that hasn't been setup correctly in the DI container (using Startup.ConfigureServices()), a blank page will be rendered for the affected component. No user-facing error is shown.
[ In addition, if the project is a Razor Components project, no exception will be logged anywhere even for the developer (for a Blazor / client-side project, an exception will be logged in the browser console). This will presumably improve as part of #7165 / #4964. ]
As a simple test case:
Startup.ConfigureServices() in the components project to add a singleton: public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<MyService>();
}
MyService. It can be left empty.MyService into Counter.cshtml: @inject MyService serviceStartup.ConfigureServices() to do nothing.This should raise an exception.
Where applicable, the developer exception page or a user-friendly error page should be shown.
The original scenario that brought this up was slightly more complicated (a service in turn depended on a second-level missing service), and thus the root issue was significantly harder to track down.
Thanks for contacting us, @chucker.
@rynowak, is this expected, or should we indeed throw?
If we throw you would get a blank screen. I'm not sure we've done any work to make the error experience reasonable yet so we should hang on to this feedback for now.
Hi @chucker - we plan to make this better in the immediate term and at least log an error to the console.
We have a more extensive long term plan to make this better as well: https://github.com/aspnet/AspNetCore/issues/8613 - but for the next release we will be fixing annoying issues like what you reported. Thanks!
HI @chucker
I've tested this out on the latest build and the current state of this is the following:
Blazor - an error is logged to the browser console.
Razor Components (Prerendering) - The developer exception page shows up. We fixed this for preview 4
Razor Components (without Prerendering) - an error is logged to the browser console.
We have some longer term plans to provide a better experience as part of #8613.
I'm closing this because a browser console error is currently what we expect to happen in preview 4.