dotnet/maui · error · InvalidOperationException
RootComponent requires a value for its ComponentType propert
Error message
RootComponent requires a value for its ComponentType property, but no value was set.
What it means
The Maui RootComponent.AddToWebViewManagerAsync method validates that ComponentType is non-null after validating Selector. Without a ComponentType, the WebViewManager has no Razor component class to instantiate and render at the selector target. This is the second validation in the pair (Selector checked first), so if you hit this error, Selector was already valid.
Source
Thrown at src/BlazorWebView/src/Maui/RootComponent.cs:46
/// <summary>
/// Gets or sets an optional dictionary of parameters to pass to the root component.
/// </summary>
public IDictionary<string, object?>? Parameters { get; set; }
internal Task AddToWebViewManagerAsync(WebViewManager webViewManager)
{
// As a characteristic of XAML,we can't rely on non-default constructors. So we have to
// validate that the required properties were set. We could skip validating this and allow
// the lower-level renderer code to throw, but that would be harder for developers to understand.
if (string.IsNullOrWhiteSpace(Selector))
{
throw new InvalidOperationException($"{nameof(RootComponent)} requires a value for its {nameof(Selector)} property, but no value was set.");
}
if (ComponentType is null)
{
throw new InvalidOperationException($"{nameof(RootComponent)} requires a value for its {nameof(ComponentType)} property, but no value was set.");
}
var parameterView = Parameters == null ? ParameterView.Empty : ParameterView.FromDictionary(Parameters);
return webViewManager.AddRootComponentAsync(ComponentType, Selector, parameterView);
}
internal Task RemoveFromWebViewManagerAsync(WebViewManager webviewManager)
{
if (string.IsNullOrWhiteSpace(Selector))
{
throw new InvalidOperationException($"{nameof(RootComponent)} requires a value for its {nameof(Selector)} property, but no value was set.");
}
return webviewManager.RemoveRootComponentAsync(Selector);
}
}
}
View on GitHub (pinned to f377ff1c5e)
Solutions
- Set ComponentType to a valid Type that implements IComponent: rc.ComponentType = typeof(MyComponent);
- In XAML, use the correct markup extension: <RootComponent Selector="#app" ComponentType="{x:Type local:MyComponent}" />.
- Ensure the assembly containing the component type is referenced and loaded at runtime.
- Verify the namespace prefix (e.g. local:) in XAML maps to the correct xmlns declaration.
Example fix
// before
var rc = new RootComponent
{
Selector = "#app"
};
// after
var rc = new RootComponent
{
Selector = "#app",
ComponentType = typeof(MyComponent)
}; Defensive patterns
Strategy: validation
Validate before calling
// Validate before adding to WebViewManager
if (rootComponent.ComponentType is null)
{
throw new InvalidOperationException("RootComponent.ComponentType must be set before adding.");
}
await rootComponent.AddToWebViewManagerAsync(webViewManager); Type guard
static bool HasComponentType(RootComponent rc)
{
return rc?.ComponentType is not null && typeof(IComponent).IsAssignableFrom(rc.ComponentType);
} Prevention
- Always set ComponentType alongside Selector when creating RootComponent.
- In XAML, verify the x:Type markup extension resolves at design time.
- Ensure the assembly containing the component type is referenced.
- Use IComponent-implementing types only.
When it happens
Trigger: A RootComponent with a valid Selector but a null ComponentType calls AddToWebViewManagerAsync. In XAML this means the ComponentType attribute was omitted or failed to resolve; in code it means the property was never assigned.
Common situations: XAML ComponentType attribute using an x:Static or x:Type markup extension that fails to resolve the type at runtime; dynamically created RootComponent where ComponentType assignment was skipped due to a conditional branch; type loading issue where the assembly containing the component was not loaded; refactor that moved the component type to a different namespace without updating the XAML.
Related errors
- RootComponent requires a value for its Selector property, bu
- RootComponent requires a value for its Selector property, bu
- RootComponent requires a value for its ComponentType propert
- 'selector' cannot be null or whitespace.
- There is no root component with selector '{selector}'.
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/e10f47806816f882.
Report an issue: GitHub.