Hello,

I have the following components in a phone page:
Code:
<maps:Map
                x:Name="Map"
                PedestrianFeaturesEnabled="True"
                LandmarksEnabled="True"
                ZoomLevel="3" Margin="0,0,0,98"
                />
<Button Content="Button" HorizontalAlignment="Left" Margin="153,514,0,0" VerticalAlignment="Top" Click="Button_Click"/>
In the main class I have:

Code:
public MapLayer pinLayer {get;set;}

public MainPage()
        {
            InitializeComponent();

            pinLayer = new MapLayer();
            Map.Layers.Add(pinLayer);
            pinLayer.Add(new MapOverlay()
                {
                    GeoCoordinate = new System.Device.Location.GeoCoordinate(40, 40),
                    PositionOrigin = new Point(0.5, 0.5),
                    Content = new Ellipse
                    {
                        Fill = new SolidColorBrush(Colors.Red),
                        Width = 20,
                        Height = 20
                    }
                }
                );

        }
Inside the click event of the button I have:
Code:
            Map.Layers.Remove(pinLayer);
            Map.Layers.Add(pinLayer);
While the command Add is being called, I have the following exception.

HTML Code:
System.ArgumentException was unhandled by user code
  HResult=-2147024809
  Message=Value does not fall within the expected range.
  Source=System.Windows
  StackTrace:
       at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
       at MS.Internal.XcpImports.Collection_InsertValue[T](PresentationFrameworkCollection`1 collection, UInt32 index, CValue value)
       at MS.Internal.XcpImports.Collection_InsertDependencyObject[T](PresentationFrameworkCollection`1 collection, UInt32 index, DependencyObject value)
       at System.Windows.PresentationFrameworkCollection`1.InsertDependencyObject(Int32 index, DependencyObject value)
       at System.Windows.Controls.UIElementCollection.InsertInternal(Int32 index, UIElement value)
       at System.Windows.PresentationFrameworkCollection`1.Insert(Int32 index, T value)
       at Microsoft.Phone.Maps.Controls.MapLayerManager.InsertItemInternal(Int32 index, MapOverlay obj)
       at Microsoft.Phone.Maps.Controls.CollectionManager`1.InsertItem(Int32 index, T item)
       at System.Collections.ObjectModel.Collection`1.Add(T item)
       at Microsoft.Phone.Maps.Controls.CollectionManager`1.AddRange(IEnumerable`1 items)
       at Microsoft.Phone.Maps.Controls.MapLayerPanel.OnMapOverlaysPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
       at Microsoft.Phone.Maps.Controls.RootLayerManager.InsertItemInternal(Int32 index, MapLayer obj)
       at Microsoft.Phone.Maps.Controls.CollectionManager`1.InsertItem(Int32 index, T item)
       at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, T item)
       at Microsoft.Phone.Maps.Controls.CollectionManager`1.CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
       at System.Collections.ObjectModel.Collection`1.Add(T item)
       at NokiaMap.MainPage.Button_Click(Object sender, RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  InnerException:
Any idea of what it may be happening or any other way where I can hide the pinLayer and then make it visible at user input?

Thank you very much.

Yours,

Efthymios Kalyviotis