{"record":{"id":"0d9517cbca9cabe6","repo":"unoplatform/uno","slug":"unable-to-find-mapgrid-template-part-0d9517","errorCode":null,"errorMessage":"Unable to find [MapGrid] template part","messagePattern":"Unable to find \\[MapGrid\\] template part","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/AddIns/Uno.UI.Maps/MapPresenter.iOS.cs","lineNumber":48,"sourceCode":"\t\tprivate MKMapView _internalMapView;\n\t\tprivate readonly Dictionary<OverlayAlias, MKOverlayRenderer> _overlayRenderers = new Dictionary<OverlayAlias, MKOverlayRenderer>();\n\t\tprivate readonly SerialDisposable _elementsDisposable = new SerialDisposable();\n\t\tprivate readonly Dictionary<DependencyObject, MapControlAnnotation> _elements = new Dictionary<DependencyObject, MapControlAnnotation>();\n\t\tprivate bool _changingCenter;\n\n\t\tprivate MapControl? _owner;\n\n\t\tprotected override void OnApplyTemplate()\n\t\t{\n\t\t\tbase.OnApplyTemplate();\n\t\t\tUpdateOwnerSubscriptions();\n\n\t\t\t_mapGrid = GetTemplateChild(\"MapGrid\") as Grid;\n\t\t\t_layerGrid = GetTemplateChild(\"LayerGrid\") as Grid;\n\n\t\t\tif (_mapGrid == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Unable to find [MapGrid] template part\");\n\t\t\t}\n\n\t\t\tif (_layerGrid == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Unable to find [LayerGrid] template part\");\n\t\t\t}\n\n\t\t\t_internalMapView = new MKMapView();\n\n\t\t\t_mapGrid.Children.Add(_internalMapView);\n\t\t\t_internalMapView.ShowsUserLocation = false;\n\n\t\t\t_internalMapView.RegionChanged += OnRegionChanged;\n\n\t\t\tOnChildrenCollectionChanged(this, null);\n\n\t\t\tSetUpOverlayRenderer();\n","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/AddIns/Uno.UI.Maps/MapPresenter.iOS.cs#L30-L66","documentation":"InvalidOperationException thrown by MapPresenter.OnApplyTemplate (iOS) when GetTemplateChild(\"MapGrid\") does not return a Grid. Identical contract to the Android variant (error 26): the iOS presenter requires a 'MapGrid' Grid template part into which it parents the native MKMapView.","triggerScenarios":"A custom ControlTemplate on MapControl/MapPresenter lacks a Grid named 'MapGrid' when running on iOS; OnApplyTemplate cannot retrieve it before creating MKMapView is added to the visual tree.","commonSituations":"Sharing a custom MapControl Style across platforms that omits the template part; iOS-specific theme override missing the named Grid; template built by a design tool that stripped x:Name.","solutions":["Include <Grid x:Name=\"MapGrid\"/> and <Grid x:Name=\"LayerGrid\"/> in any custom MapControl template (mirror Generic.xaml).","Avoid platform-specific template divergence unless you also duplicate the required parts per platform.","Validate the applied template at runtime by enumerating the visual tree.","Fall back to the default template to isolate whether the custom Style is the cause."],"exampleFix":"// before — iOS custom template without MapGrid\n<ControlTemplate><ContentPresenter/></ControlTemplate>\n\n// after\n<ControlTemplate>\n  <Grid>\n    <Grid x:Name=\"MapGrid\"/>\n    <Grid x:Name=\"LayerGrid\"/>\n  </Grid>\n</ControlTemplate>","handlingStrategy":"validation","validationCode":"var mapGrid = mapControl.GetTemplateChild(\"MapGrid\") as Grid;\nif (mapGrid == null) throw new InvalidOperationException(\"Custom template missing MapGrid (iOS)\");","typeGuard":"bool TemplateHasMapGrid(Control c)\n    => c.GetTemplateChild(\"MapGrid\") is Grid;","tryCatchPattern":"try { /* OnApplyTemplate logic */ }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"MapGrid\"))\n{ Log.Error(\"MapControl (iOS) template missing MapGrid part\"); }","preventionTips":["Keep the MapGrid template part in any iOS custom MapControl template.","Share templates only if all required parts are present on every platform.","Inspect the visual tree at runtime on iOS to confirm parts resolve."],"tags":["maps","control-template","template-part","ios","uno-platform"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}