{"record":{"id":"401d81c0acd3be90","repo":"dotnet/maui","slug":"could-not-find-or-create-a-renderer-for-view","errorCode":null,"errorMessage":"Could not find or create a renderer for {view}","messagePattern":"Could not find or create a renderer for (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Extensions/PageExtensions.cs","lineNumber":30,"sourceCode":"\n\t\t\tif (!(view.RealParent is Application))\n\t\t\t{\n\t\t\t\tApplication app = new DefaultApplication\n\t\t\t\t{\n\t\t\t\t\tMainPage = view\n\t\t\t\t};\n\n\t\t\t\tvar formsApplicationPage = new FormsApplicationPage();\n\t\t\t\tformsApplicationPage.LoadApplication(app);\n\t\t\t\tvar platform = new Platform(formsApplicationPage);\n\t\t\t\tplatform.SetPage(view);\n\t\t\t}\n\n\t\t\tIVisualElementRenderer renderer = Platform.GetOrCreateRenderer(view);\n\n\t\t\tif (renderer == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException($\"Could not find or create a renderer for {view}\");\n\t\t\t}\n\n\t\t\tvar frameworkElement = renderer.GetNativeElement();\n\n\t\t\tframeworkElement.Loaded += (sender, args) =>\n\t\t\t{\n\t\t\t\tview.Layout(new Rectangle(0, 0, frameworkElement.ActualWidth, frameworkElement.ActualHeight));\n\t\t\t};\n\n\t\t\treturn frameworkElement;\n\t\t}\n\t}\n\n\tclass DefaultApplication : Application\n\t{\n\t}\n}\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Extensions/PageExtensions.cs#L12-L48","documentation":"PageExtensions.ToFrameworkElement throws InvalidOperationException($\"Could not find or create a renderer for {view}\") when Platform.GetOrCreateRenderer(view) returns null. This means no renderer is registered for the view's type in the WPF renderer registrar (or the type is a layout/group with no platform mapping).","triggerScenarios":"Passing a Page/View whose type has no ExportRenderer registration on WPF; using a custom control without registering its renderer; referencing a Forms type whose WPF backend exists in an assembly that was not loaded before registrar init.","commonSituations":"Custom view missing [assembly: ExportRenderer]; renderer assembly not referenced/loaded at Forms.Init(); using a control from a compatibility pack whose WPF renderer is absent; calling ToFrameworkElement on a non-VisualElement.","solutions":["Register a WPF renderer for the view type via [assembly: ExportRenderer(typeof(MyView), typeof(MyViewRenderer))].","Ensure the renderer assembly is loaded before Forms.Init() (call a static type from it, or pass it to Forms.Init).","Confirm the view type is a VisualElement subclass that the WPF platform supports.","If the type is unsupported on WPF, fall back to a host page or a custom renderer."],"exampleFix":"// before\n[assembly: ExportRenderer(typeof(MyView), typeof(MyViewRenderer))]\n// renderer assembly never loaded at runtime\n\n// after\n// force-load the renderer assembly, then init\nSystem.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(MyApp.Renderers.Registration).TypeHandle);\nForms.Init();","handlingStrategy":"validation","validationCode":"if (Platform.GetOrCreateRenderer(view) == null) throw new InvalidOperationException($\"No renderer for {view.GetType()}\");","typeGuard":"static bool HasRenderer(VisualElement v) => Platform.GetOrCreateRenderer(v) != null;","tryCatchPattern":"try { return view.ToFrameworkElement(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"renderer\"))\n{ /* register renderer assembly, then retry once */ }","preventionTips":["Register WPF renderers via ExportRenderer for every custom view.","Force-load renderer assemblies before Forms.Init().","Add a smoke test asserting ToFrameworkElement returns non-null for each top-level page."],"tags":["wpf","renderer","registrar","missing-registration","startup"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}