dotnet/maui · error · InvalidOperationException
Unable to find the required services. Please add all the req
Error message
Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddWpfBlazorWebView' in the application startup code.
What it means
The WebView2WebViewManager constructor, compiled under the WEBVIEW2_WPF directive (#elif), checks that WpfBlazorMarkerService is registered. This marker is added exclusively by AddWpfBlazorWebView(). Without it, the Blazor services for WPF (component rendering, JS interop, dispatcher marshalling) were never set up. The check is the WPF counterpart of the WinForms marker check.
Source
Thrown at src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs:114
Action<BlazorWebViewInitializingEventArgs> blazorWebViewInitializing,
Action<BlazorWebViewInitializedEventArgs> blazorWebViewInitialized,
ILogger logger)
: base(services, dispatcher, AppOriginUri, fileProvider, jsComponents, hostPagePathWithinFileProvider)
{
ArgumentNullException.ThrowIfNull(webview);
#if WEBVIEW2_WINFORMS
if (services.GetService<WindowsFormsBlazorMarkerService>() is null)
{
throw new InvalidOperationException(
"Unable to find the required services. " +
$"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddWindowsFormsBlazorWebView)}' in the application startup code.");
}
#elif WEBVIEW2_WPF
if (services.GetService<WpfBlazorMarkerService>() is null)
{
throw new InvalidOperationException(
"Unable to find the required services. " +
$"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddWpfBlazorWebView)}' in the application startup code.");
}
#endif
_logger = logger;
_webview = webview;
_urlLoading = urlLoading;
_blazorWebViewInitializing = blazorWebViewInitializing;
_blazorWebViewInitialized = blazorWebViewInitialized;
_developerTools = services.GetRequiredService<BlazorWebViewDeveloperTools>();
_contentRootRelativeToAppRoot = contentRootRelativeToAppRoot;
// Unfortunately the CoreWebView2 can only be instantiated asynchronously.
// We want the external API to behave as if initalization is synchronous,
// so keep track of a task we can await during LoadUri.
_webviewReadyTask = TryInitializeWebView2();
}View on GitHub (pinned to f377ff1c5e)
Solutions
- Call services.AddWpfBlazorWebView() on your IServiceCollection in App.xaml.cs or the window constructor before creating the BlazorWebView.
- Ensure the ServiceProvider passed to the BlazorWebView Services property is the built result of the collection that had AddWpfBlazorWebView called.
- Double-check you are calling the WPF variant (AddWpfBlazorWebView), not the WinForms or MAUI variant.
- If using a DI container like Autofac or Lamar, ensure the marker service singleton is registered through the adapter.
Example fix
// before var services = new ServiceCollection(); services.AddWindowsFormsBlazorWebView(); // wrong platform! var sp = services.BuildServiceProvider(); // after var services = new ServiceCollection(); services.AddWpfBlazorWebView(); var sp = services.BuildServiceProvider();
Defensive patterns
Strategy: validation
Validate before calling
// Verify marker service is registered before creating BlazorWebView
var services = new ServiceCollection();
services.AddWpfBlazorWebView();
var sp = services.BuildServiceProvider();
if (sp.GetService<WpfBlazorMarkerService>() is null)
{
throw new InvalidOperationException("AddWpfBlazorWebView was not called.");
} Try / catch
try
{
// Code that creates/initializes a WPF BlazorWebView
}
catch (InvalidOperationException ex) when (ex.Message.Contains("AddWpfBlazorWebView"))
{
logger.LogError(ex, "WPF Blazor services not registered. Call AddWpfBlazorWebView.");
throw;
} Prevention
- Call AddWpfBlazorWebView() in App.xaml.cs before any BlazorWebView is created.
- Double-check you are using the WPF variant, not WinForms or MAUI.
- Pass the configured ServiceProvider to the BlazorWebView Services property.
- Add a smoke test that verifies WpfBlazorMarkerService is registered.
When it happens
Trigger: A WebView2WebViewManager is constructed when a WPF BlazorWebView control initializes, but the IServiceProvider lacks WpfBlazorMarkerService. This occurs when App.xaml.cs or the window's constructor does not call AddWpfBlazorWebView() on the service collection before the BlazorWebView is created.
Common situations: WPF application that creates a BlazorWebView in XAML or code without calling AddWpfBlazorWebView in the service configuration; using AddWindowsFormsBlazorWebView by mistake in a WPF project; ServiceProvider created before the registration call; package upgrade where the method was renamed or the directive changed.
Related errors
- Unable to find the required services. Please add all the req
- Unable to find the required services. Please add all the req
- Unable to find the required services. Please add all the req
- Unable to find the required services. Please add all the req
- Can't start BlazorWebView without native web view instance.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/75e440824c600b9e.
Report an issue: GitHub.