AnsweredAssumed Answered

Exception casting/QI to IGeometry5

Question asked by keithgemeinhart on Sep 27, 2012
Latest reply on Sep 28, 2012 by keithgemeinhart
Given the following code, I'm seeing InvalidCast exceptions on the members of IGeometry5 interface. The last line executes without exception, but if you look at the object in the watch window, then you can see the problem:


Am I doing something wrong or is this a bug? I first identified the problem when I was trying to serialize to Json, but it appears the serialization did not like the fact that all of these members of IGeometry5 are invalid.

This is ArcObjects 10.1 .... more specifically, I'm using the C/JMTK build, but I don't think that makes a difference.

            //pPointColl is the new polyline.             IPointCollection pPointColl = new PolylineClass();              //TODO:             IPoint pt = new Point();             pt.PutCoords(10, 0);             pt.Z = 1;             pt.ID = 1;             pPointColl.AddPoint(pt);              pt = new Point();             pt.PutCoords(10, 10);             pt.Z = 0;             pt.ID = 2;             pPointColl.AddPoint(pt);              pt = new Point();             pt.PutCoords(20, 10);             pt.Z = 0;              pt.ID = 3;             pPointColl.AddPoint(pt);              pt = new Point();             pt.PutCoords(20, 0);             pt.Z = 0;              pt.ID = 4;             pPointColl.AddPoint(pt);              (pPointColl as IPolyline).SpatialReference = MyCodeLib.DefaultSpatialReference();             (pPointColl as IZAware).ZAware = true;              var itopo = (ITopologicalOperator) pPointColl;             itopo.Simplify();              IGeometry5 geom5 = (IGeometry5) pPointColl;