{"record":{"id":"d3ddea0bac4c0aae","repo":"dotnet/maui","slug":"new-element-must-be-a-carouselpage","errorCode":null,"errorMessage":"New element must be a CarouselPage","messagePattern":"New element must be a CarouselPage","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/GTK/Renderers/CarouselPageRenderer.cs","lineNumber":65,"sourceCode":"\n\t\t\tbase.Dispose(disposing);\n\t\t}\n\n\t\tprotected override void OnElementChanged(VisualElementChangedEventArgs e)\n\t\t{\n\t\t\tbase.OnElementChanged(e);\n\n\t\t\tif (e.OldElement != null)\n\t\t\t{\n\t\t\t\tPage.PagesChanged -= OnPagesChanged;\n\t\t\t}\n\n\t\t\tif (e.NewElement != null)\n\t\t\t{\n\t\t\t\tvar newPage = e.NewElement as CarouselPage;\n\n\t\t\t\tif (newPage == null)\n\t\t\t\t\tthrow new ArgumentException(\"New element must be a CarouselPage\");\n\n\t\t\t\tif (Widget == null)\n\t\t\t\t{\n\t\t\t\t\tWidget = new Carousel();\n\t\t\t\t\tWidget.Animated = true;\n\n\t\t\t\t\tvar eventBox = new GtkFormsContainer();\n\t\t\t\t\teventBox.Add(Widget);\n\t\t\t\t\tControl.Content = eventBox;\n\t\t\t\t}\n\n\t\t\t\tInit();\n\t\t\t}\n\t\t}\n\n\t\tprotected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)\n\t\t{\n\t\t\tbase.OnElementPropertyChanged(sender, e);","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/GTK/Renderers/CarouselPageRenderer.cs#L47-L83","documentation":"CarouselPageRenderer.OnElementChanged casts e.NewElement to CarouselPage; if the element is any other Page type the cast yields null and it throws ArgumentException. The renderer is registered for CarouselPage specifically, so a non-CarouselPage element reaching it means a registration mismatch or a wrong element assignment. The same pattern is used across renderers (e.g. TabbedPageRenderer) to fail fast on type violations.","triggerScenarios":"A renderer is explicitly bound to CarouselPage (via ExportRenderer or the default registration) but receives a ContentPage/TabbedPage/other Page. Can also occur if Element is manually swapped to an incompatible type, or a custom ExportRenderer attribute misroutes the type.","commonSituations":"Wrong ExportRenderer registration (registering CarouselPageRenderer for ContentPage). Copy-paste of renderer registration across page types. Manually assigning an incompatible element to a renderer during custom rendering.","solutions":["Ensure the page being rendered is actually a CarouselPage (new CarouselPage { Children = ... }).","Check any [assembly: ExportRenderer(typeof(...), typeof(CarouselPageRenderer))] attribute maps CarouselPage, not another page type.","If subclassing CarouselPage, confirm the subclass is still assignable to CarouselPage and that the renderer is registered for the base type."],"exampleFix":"// before (wrong registration)\n[assembly: ExportRenderer(typeof(ContentPage), typeof(CarouselPageRenderer))]\n\n// after\n[assembly: ExportRenderer(typeof(CarouselPage), typeof(CarouselPageRenderer))]","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsCarousel(Page p) => p is CarouselPage;\n// before assigning/using:\nif (!IsCarousel(myPage)) throw new InvalidOperationException(\"CarouselPage required\");","tryCatchPattern":null,"preventionTips":["Register renderers against the exact page type they handle.","When subclassing, keep renderer registration aligned with the assignable type.","Audit ExportRenderer attributes after refactors."],"tags":["gtk","renderer","carousel","type-mismatch","maui","xamarin"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}