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 IOSWebViewManager constructor (unconditionally, without a #if guard unlike the Android variant) checks that MauiBlazorMarkerService is registered in the IServiceProvider. This marker is only added by AddMauiBlazorWebView(). If absent, the Blazor services were never registered, and attempting to render components on iOS would fail with confusing null references downstream. The check provides an actionable error message instead.

Source

Thrown at src/BlazorWebView/src/Maui/iOS/IOSWebViewManager.cs:51

		/// <param name="blazorMauiWebViewHandler">The <see cref="BlazorWebViewHandler"/>.</param>
		/// <param name="webview">The <see cref="WKWebView"/> to render web content in.</param>
		/// <param name="provider">The <see cref="IServiceProvider"/> for the application.</param>
		/// <param name="dispatcher">A <see cref="Dispatcher"/> instance instance that can marshal calls to the required thread or sync context.</param>
		/// <param name="fileProvider">Provides static content to the webview.</param>
		/// <param name="jsComponents">Describes configuration for adding, removing, and updating root components from JavaScript code.</param>
		/// <param name="contentRootRelativeToAppRoot">Path to the directory containing application content files.</param>
		/// <param name="hostPageRelativePath">Path to the host page within the fileProvider.</param>
		/// <param name="logger">Logger to send log messages to.</param>

		public IOSWebViewManager(BlazorWebViewHandler blazorMauiWebViewHandler, WKWebView webview, IServiceProvider provider, Dispatcher dispatcher, IFileProvider fileProvider, JSComponentConfigurationStore jsComponents, string contentRootRelativeToAppRoot, string hostPageRelativePath, ILogger logger)
			: base(provider, dispatcher, BlazorWebViewHandler.AppOriginUri, fileProvider, jsComponents, hostPageRelativePath)
		{
			ArgumentNullException.ThrowIfNull(blazorMauiWebViewHandler);
			ArgumentNullException.ThrowIfNull(webview);

			if (provider.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;
			_blazorMauiWebViewHandler = blazorMauiWebViewHandler;
			_webview = webview;
			_contentRootRelativeToAppRoot = contentRootRelativeToAppRoot;

			InitializeWebView();
		}

		/// <inheritdoc />
		protected override void NavigateCore(Uri absoluteUri)
		{
			_logger.NavigatingToUri(absoluteUri);
			using var nsUrl = new NSUrl(absoluteUri.ToString());
			using var request = new NSUrlRequest(nsUrl);

View on GitHub (pinned to f377ff1c5e)

Solutions

  1. Call builder.Services.AddMauiBlazorWebView() in MauiProgram.CreateMauiApp before builder.Build().
  2. If using ConfigureServices, ensure it runs: builder.UseMauiApp<App>().Services.AddMauiBlazorWebView().
  3. Verify that the IServiceProvider passed to the handler is the root provider from the MAUI host, not a manually constructed one.
  4. Check for conditional compilation (#if IOS) blocks that might skip the registration on iOS.

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
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 IOSWebViewManager
}
catch (InvalidOperationException ex) when (ex.Message.Contains("AddMauiBlazorWebView"))
{
    logger.LogError(ex, "Blazor services not registered for iOS. Call AddMauiBlazorWebView in MauiProgram.");
    throw;
}

Prevention

When it happens

Trigger: An IOSWebViewManager is constructed with a provider that lacks MauiBlazorMarkerService. This happens when the BlazorWebViewHandler on iOS creates its manager but MauiProgram.CreateMauiApp did not call AddMauiBlazorWebView, or the provider passed to the handler is not the one configured by MAUI's hosting pipeline.

Common situations: Forgetting to call AddMauiBlazorWebView() in MauiProgram.cs; upgrading MAUI/BlazorWebView packages where the registration API changed; using a custom IServiceProvider or DI container that does not flow the marker singleton; iOS-specific code path that constructs the handler differently from other platforms; conditional service registration that skips iOS.

Related errors


AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13). Data as JSON: /api/errors/5913e2d1b59ea923. Report an issue: GitHub.