{"record":{"id":"de7f6e4ee0691f32","repo":"dotnet/maui","slug":"unable-to-find-the-required-services-please-add-a-de7f6e","errorCode":null,"errorMessage":"Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddMauiBlazorWebView' in the application startup code.","messagePattern":"Unable to find the required services\\. Please add all the required services by calling 'IServiceCollection\\.AddMauiBlazorWebView' in the application startup code\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs","lineNumber":166,"sourceCode":"\t\t/// <param name=\"logger\">Logger to send log messages to.</param>\n\t\tinternal WebView2WebViewManager(\n\t\t\tWebView2Control webview,\n\t\t\tIServiceProvider services,\n\t\t\tDispatcher dispatcher,\n\t\t\tIFileProvider fileProvider,\n\t\t\tJSComponentConfigurationStore jsComponents,\n\t\t\tstring contentRootRelativeToAppRoot,\n\t\t\tstring hostPagePathWithinFileProvider,\n\t\t\tBlazorWebViewHandler blazorWebViewHandler,\n\t\t\tILogger logger\n\t\t)\n\t\t\t: base(services, dispatcher, AppOriginUri, fileProvider, jsComponents, hostPagePathWithinFileProvider)\n\t\t{\n\t\t\tArgumentNullException.ThrowIfNull(webview);\n\n\t\t\tif (services.GetService<MauiBlazorMarkerService>() is null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\n\t\t\t\t\t\"Unable to find the required services. \" +\n\t\t\t\t\t$\"Please add all the required services by calling '{nameof(IServiceCollection)}.{nameof(BlazorWebViewServiceCollectionExtensions.AddMauiBlazorWebView)}' in the application startup code.\");\n\t\t\t}\n\n\t\t\t_logger = logger;\n\t\t\t_webview = webview;\n\t\t\t_blazorWebViewHandler = blazorWebViewHandler;\n\t\t\t_contentRootRelativeToAppRoot = contentRootRelativeToAppRoot;\n\n\t\t\t// Unfortunately the CoreWebView2 can only be instantiated asynchronously.\n\t\t\t// We want the external API to behave as if initalization is synchronous,\n\t\t\t// so keep track of a task we can await during LoadUri.\n\t\t\t_webviewReadyTask = TryInitializeWebView2();\n\t\t}\n#endif\n\n\t\t/// <inheritdoc />\n\t\tprotected override void NavigateCore(Uri absoluteUri)","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/BlazorWebView/src/SharedSource/WebView2WebViewManager.cs#L148-L184","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic static MauiApp CreateMauiApp(MauiAppBuilder builder)\n{\n    builder.UseMauiApp<App>();\n    return builder.Build();\n}\n// after\npublic static MauiApp CreateMauiApp(MauiAppBuilder builder)\n{\n    builder.UseMauiApp<App>()\n           .Services.AddMauiBlazorWebView();\n    return builder.Build();\n}","handlingStrategy":"validation","validationCode":"// Verify marker service is registered for MAUI/Windows\nvar services = new ServiceCollection();\nservices.AddMauiBlazorWebView();\nvar sp = services.BuildServiceProvider();\nif (sp.GetService<MauiBlazorMarkerService>() is null)\n{\n    throw new InvalidOperationException(\"AddMauiBlazorWebView was not called.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    // Code that constructs the MAUI WebView2WebViewManager\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AddMauiBlazorWebView\"))\n{\n    logger.LogError(ex, \"MAUI Blazor services not registered for Windows. Call AddMauiBlazorWebView.\");\n    throw;\n}","preventionTips":["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."],"tags":["blazor","blazorwebview","maui","windows","dependency-injection","service-registration","webview2"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}