dotnet/maui · error · InvalidOperationException
Could not find or create a renderer for {visualElement}
Error message
Could not find or create a renderer for {visualElement} What it means
Thrown by ToFrameworkElement when GetOrCreateRenderer returns null for a VisualElement. The method first checks Forms.IsInitialized, creates a WindowsPlatform, then calls GetOrCreateRenderer which delegates to Platform.CreateRenderer. CreateRenderer tries the MAUI handler registry, then falls back to the Registrar, then DefaultRenderer. If the entire chain yields null (e.g. handler registration silently swallowed an exception and Registrar returned null without DefaultRenderer fallback on a code path), the InvalidOperationException fires.
Source
Thrown at src/Compatibility/Core/src/Windows/PageExtensions.cs:69
}
internal static FrameworkElement ToFrameworkElement(this VisualElement visualElement)
{
if (!Forms.IsInitialized)
{
throw new InvalidOperationException("call Forms.Init() before this");
}
var root = new Microsoft.UI.Xaml.Window();
// Yes, this looks awkward. But the page needs to be Platformed or several things won't work
new WindowsPlatform(root);
var renderer = visualElement.GetOrCreateRenderer();
if (renderer == null)
{
throw new InvalidOperationException($"Could not find or create a renderer for {visualElement}");
}
var frameworkElement = renderer.ContainerElement;
frameworkElement.Loaded += (sender, args) =>
{
visualElement.Layout(new Rect(0, 0, frameworkElement.ActualWidth, frameworkElement.ActualHeight));
};
return frameworkElement;
}
public static bool Navigate(this Microsoft.UI.Xaml.Controls.Frame frame, ContentPage page)
{
return Navigate(frame, page, null);
}
internal static bool Navigate(this Microsoft.UI.Xaml.Controls.Frame frame, ContentPage page, Microsoft.UI.Xaml.Media.Animation.NavigationTransitionInfo infoOverride)View on GitHub (pinned to f377ff1c5e)
Solutions
- Register a renderer for the element type: [assembly: ExportRenderer(typeof(MyCustomView), typeof(MyCustomViewRenderer))] in a platform assembly
- Ensure Forms.Init() or MauiProgram.CreateMauiApp() is called before invoking ToFrameworkElement
- Verify the VisualElement type has a built-in renderer by checking the Registrar has a handler for element.GetType()
- If embedding a standard Page, confirm the page hierarchy only contains types with registered WinUI renderers
Example fix
// before var fe = myCustomView.ToFrameworkElement(); // throws if no renderer registered // after [assembly: ExportRenderer(typeof(MyCustomView), typeof(MyCustomViewRenderer))] // ... then: var fe = myCustomView.ToFrameworkElement();
Defensive patterns
Strategy: validation
Validate before calling
// Before calling ToFrameworkElement, verify a renderer is available
var renderer = Platform.GetRenderer(visualElement);
if (renderer == null)
{
// Check if the Registrar has a handler for this type
var hasHandler = Microsoft.Maui.Controls.Internals.Registrar.Registered
.GetHandlerForObject<IVisualElementRenderer>(visualElement) != null;
if (!hasHandler)
throw new InvalidOperationException($"No renderer registered for {visualElement.GetType()}");
}
var fe = visualElement.ToFrameworkElement(); Type guard
static bool HasRegisteredRenderer(VisualElement element)
{
return Microsoft.Maui.Controls.Internals.Registrar.Registered
.GetHandlerForObject<IVisualElementRenderer>(element) != null;
} Try / catch
try
{
var fe = visualElement.ToFrameworkElement();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find or create a renderer"))
{
// Log the element type for diagnostics
Console.Error.WriteLine($"No renderer for {visualElement.GetType().Name}. Register via ExportRenderer.");
throw;
} Prevention
- Register all custom renderers via [assembly: ExportRenderer] in a platform-specific assembly
- Ensure Forms.Init() or MauiProgram.CreateMauiApp() runs before any renderer-dependent API
- Verify renderer registration in unit tests by checking Registrar.Registered.GetHandler
When it happens
Trigger: Calling page.CreateFrameworkElement() or page.ToFrameworkElement() on a custom VisualElement whose type has no registered renderer or handler. Embedding a Forms ContentPage into a native WinUI page via FormsEmbeddedPageWrapper when the page's content type lacks renderer registration.
Common situations: Custom control missing [assembly: ExportRenderer] or handler registration; migration from Xamarin.Forms to MAUI Compatibility where renderer registration semantics changed; platform-specific renderer assembly not loaded at startup; element is a type only supported on iOS/Android but not WinUI.
Related errors
- PushAsync is not supported globally on Windows, please use a
- PopAsync is not supported globally on Windows, please use a
- PopToRootAsync is not supported globally on Windows, please
- RemovePage is not supported globally on Windows, please use
- InsertPageBefore is not supported globally on Windows, pleas
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/78fbb11a28f37c55.
Report an issue: GitHub.