1

Closed

Shape.Id throws InvalidCastException

description

After creating a shape and adding it to a layer, if you try to access the Id property you get the following exception:
 
System.InvalidCastException was unhandled by user code
Message="Invalid cast from 'System.String' to 'System.Windows.Browser.ScriptObject'."
 
Sample code:
            VELatLong location = new VELatLong(cover.Latitude, cover.Longitude);
            VEShape pin = new VEShape(VEShapeType.Pushpin,location);
            pin.CustomIcon = "images/MapPinRed.png";
            pin.Point = location;
            pin.Title = cover.Album + " - " + cover.Artist;
            pin.Description = cover.Location ;
            pin.PhotoUrl = new Uri(cover.ImageUrl);
            albumLayer.AddShape(pin);
            string pinId = pin.Id; // <== Exception thrown here
Closed Aug 18, 2008 at 8:02 AM by IanBlackburn

comments

IanBlackburn wrote Jul 24, 2008 at 8:18 AM

In VEShape.cs the ID Property so is null, and the ConvertTo is faling.

As a workaround the following produces the desired result, retuning the correct ID, or null if the shape is not added to a layer;

public string Id
    {
        get
        {
            //ScriptObject so = Invoke<ScriptObject>("GetID");
            //Debug.Assert(so == null, "Shape not part of a layer");
            //if (so == null)
            //    return "";
            //return so.ConvertTo<string>();
            return Invoke<string>("GetID");
        }
    }

wrote Aug 18, 2008 at 8:02 AM

Resolved with changeset 15144.

wrote Feb 12, 2013 at 7:16 PM

wrote May 14, 2013 at 10:33 PM