{"record":{"id":"c9281ebbacdb34ff","repo":"dotnet/maui","slug":"pin-must-have-a-label-to-be-added-to-a-map","errorCode":null,"errorMessage":"Pin must have a Label to be added to a map","messagePattern":"Pin must have a Label to be added to a map","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Controls/Maps/src/Map.cs","lineNumber":231,"sourceCode":"\t\t\t{\n\t\t\t\tthrow new ArgumentNullException(nameof(visibleRegion));\n\t\t\t}\n\n\t\t\tif (_visibleRegion == visibleRegion)\n\t\t\t{\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tOnPropertyChanging(nameof(VisibleRegion));\n\t\t\t_visibleRegion = visibleRegion;\n\t\t\tOnPropertyChanged(nameof(VisibleRegion));\n\t\t}\n\n\t\tvoid PinsOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)\n\t\t{\n\t\t\tif (e.NewItems is not null && e.NewItems.Cast<Pin>().Any(pin => pin.Label is null))\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"Pin must have a Label to be added to a map\");\n\t\t\t}\n\n\t\t\tHandler?.UpdateValue(nameof(IMap.Pins));\n\t\t}\n\n\t\tvoid MapElementsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)\n\t\t{\n\t\t\tHandler?.UpdateValue(nameof(IMap.Elements));\n\t\t\tif (e.NewItems is not null)\n\t\t\t{\n\t\t\t\tforeach (MapElement item in e.NewItems)\n\t\t\t\t{\n\t\t\t\t\titem.PropertyChanged += MapElementPropertyChanged;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (e.OldItems is not null)\n\t\t\t{","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/Maps/src/Map.cs#L213-L249","documentation":"The Map control validates pins added to its Pins collection. When a Pin is added whose Label is null, PinsOnCollectionChanged throws ArgumentException because map platforms (iOS Maps, Android Google Maps, etc.) require a non-null label to display and identify a pin annotation. Without a label the pin is unusable on all native map renderers.","triggerScenarios":"Adding a Pin to `Map.Pins` (or assigning ItemsSource that generates pins) where at least one Pin has a null Label. Occurs during `map.Pins.Add(new Pin { Location = ... })` without setting Label, or when a data-binding for Label resolves to null.","commonSituations":"Binding Pins to a collection where the label property is nullable or occasionally null. Creating pins from geocoding results where the place name is missing. ItemsSource data templates that don't bind Label. Programmatic pin creation from API responses with optional name fields.","solutions":["Always set Pin.Label before adding it to the Map: `new Pin { Label = \"My Location\", Location = loc }`.","When using ItemsSource and ItemTemplate, ensure the Label binding target is non-null: `Label=\"{Binding Name}\"` where Name is guaranteed.","Filter or default null labels before adding pins: `Label = place.Name ?? \"Unknown\"`.","If populating from async data, add the pin only after the label is resolved."],"exampleFix":"// before\nmap.Pins.Add(new Pin\n{\n    Location = new Location(47.6, -122.3)\n    // Label missing\n});\n\n// after\nmap.Pins.Add(new Pin\n{\n    Label = \"Seattle\",\n    Location = new Location(47.6, -122.3)\n});","handlingStrategy":"validation","validationCode":"// Validate before adding to Map.Pins\nvar pin = new Pin { Location = loc };\nif (string.IsNullOrEmpty(pin.Label))\n    pin.Label = \"Unknown\";\nmap.Pins.Add(pin);\n\n// Or filter a collection\nforeach (var p in pinList.Where(p => !string.IsNullOrEmpty(p.Label)))\n    map.Pins.Add(p);","typeGuard":"static bool HasValidLabel(Pin pin) => !string.IsNullOrEmpty(pin.Label);","tryCatchPattern":null,"preventionTips":["Always set Pin.Label when constructing pins programmatically.","In ItemTemplate data bindings, bind Label to a non-nullable source property.","Default null labels to a placeholder string before adding to the map."],"tags":["maui","maps","pin","argument","validation","collection-changed"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}