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.AddMauiBlazorWebView' in the application startup code.
What it means
The MAUI-specific WebView2WebViewManager constructor overload (distinct from the WinForms/WPF overloads) checks that MauiBlazorMarkerService is registered. This is the Windows-side check for MAUI apps using WebView2 as the backing engine. The marker is added by AddMauiBlazorWebView(), which also registers the BlazorWebViewHandler in the MAUI handler pipeline.
Source
Thrown at src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs:166
/// <param name="logger">Logger to send log messages to.</param>
internal WebView2WebViewManager(
WebView2Control webview,
IServiceProvider services,
Dispatcher dispatcher,
IFileProvider fileProvider,
JSComponentConfigurationStore jsComponents,
string contentRootRelativeToAppRoot,
string hostPagePathWithinFileProvider,
BlazorWebViewHandler blazorWebViewHandler,
ILogger logger
)
: base(services, dispatcher, AppOriginUri, fileProvider, jsComponents, hostPagePathWithinFileProvider)
{
ArgumentNullException.ThrowIfNull(webview);
if (services.GetService<MauiBlazorMarkerService>() is null)
{
throw new InvalidOperationException(
"Unable to find the required services. " +
$"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView)}' in the application startup code.");
}
_logger = logger;
_webview = webview;
_blazorWebViewHandler = blazorWebViewHandler;
_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();
}
#endif
/// <inheritdoc />
protected override void NavigateCore(Uri absoluteUri)View on GitHub (pinned to f377ff1c5e)
Solutions
- Call builder.Services.AddMauiBlazorWebView() in MauiProgram.CreateMauiApp.
- Ensure you call AddMauiBlazorWebView (not AddWindowsFormsBlazorWebView or AddWpfBlazorWebView) in a MAUI project.
- Verify the IServiceProvider passed to the handler is from the MAUI host, not a manually constructed one.
- Check that Microsoft.AspNetCore.Components.WebView.Maui and Microsoft.Maui.Controls packages are version-aligned.
Example fix
// before
public static MauiApp CreateMauiApp(MauiAppBuilder builder)
{
builder.UseMauiApp<App>();
return builder.Build();
}
// after
public static MauiApp CreateMauiApp(MauiAppBuilder builder)
{
builder.UseMauiApp<App>()
.Services.AddMauiBlazorWebView();
return builder.Build();
} Defensive patterns
Strategy: validation
Validate before calling
// Verify marker service is registered for MAUI/Windows
var services = new ServiceCollection();
services.AddMauiBlazorWebView();
var sp = services.BuildServiceProvider();
if (sp.GetService<MauiBlazorMarkerService>() is null)
{
throw new InvalidOperationException("AddMauiBlazorWebView was not called.");
} Try / catch
try
{
// Code that constructs the MAUI WebView2WebViewManager
}
catch (InvalidOperationException ex) when (ex.Message.Contains("AddMauiBlazorWebView"))
{
logger.LogError(ex, "MAUI Blazor services not registered for Windows. Call AddMauiBlazorWebView.");
throw;
} Prevention
- Call AddMauiBlazorWebView() in MauiProgram.CreateMauiApp.
- Use AddMauiBlazorWebView (not AddWindowsFormsBlazorWebView or AddWpfBlazorWebView) in MAUI projects.
- Keep Microsoft.AspNetCore.Components.WebView.Maui and Microsoft.Maui.Controls versions aligned.
- Add a startup test verifying MauiBlazorMarkerService is present.
When it happens
Trigger: The MAUI WebView2WebViewManager constructor is called (when a BlazorWebView on Windows MAUI initializes) with an IServiceProvider that lacks MauiBlazorMarkerService. This happens when MauiProgram.CreateMauiApp does not call AddMauiBlazorWebView, or when a custom ServiceProvider is passed to the handler that bypasses the MAUI host configuration.
Common situations: MAUI app targeting Windows that forgot AddMauiBlazorWebView in ConfigureServices; using AddWindowsFormsBlazorWebView or AddWpfBlazorWebView instead of AddMauiBlazorWebView in a MAUI project; package version mismatch between Microsoft.AspNetCore.Components.WebView.Maui and Microsoft.Maui.Controls; handler customization that replaces the ServiceProvider.
Related errors
- Unable to find the required services. Please add all the req
- Can't start BlazorWebView without native web view instance.
- 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
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/de7f6e4ee0691f32.
Report an issue: GitHub.