Create IPolyline with two IPoints- 'Zero-Length polylines not allowed

Discussion created by alokmishra2003 on May 26, 2013
Latest reply on May 27, 2013 by
I want to create a simple IPolyline with having two IPoints. But getting error: 'Zero-Length polylines not allowed.'

Sample code is given below.

private void CreateNewFeature(IFeatureWorkspace pFeatureWorkspace,string sClassName, IPoint pPointFrom, IPoint pPointTo)


IFeature pFeatureNew = default(IFeature);

IPolyline pPolyLine = default(IPolyline);

IFeatureClass pFeatClass = default(IFeatureClass);

object pBefore, pAfter;

IPointCollection pPointCollection = new Polyline();



pFeatClass = pFeatureWorkspace.OpenFeatureClass(sClassName);

pPolyLine = new PolylineClass();

//pPolyLine.FromPoint = pPointFrom;

//pPolyLine.ToPoint = pPointTo;

pBefore = Type.Missing;

pAfter = Type.Missing;

pPointCollection.AddPoint(pPointFrom, ref pBefore, ref pAfter);

pPointCollection.AddPoint(pPointTo, ref pBefore, ref pAfter);

pFeatureNew = pFeatClass.CreateFeature();

pFeatureNew.Shape = (IGeometry)pPointCollection;



catch (Exception ex)




Please help me out, what am I missing here? Thanks in advance.