I'm new in programming . i'd like to write a simple code that can create offset from a polyline . i wrote the below code but when run the code i encounter to the error " Null reference exception was unhandled by user code" in line construct.ConstructOffset(pfeaturelayer as IPolyline, 100.3 , missing,missing); how can i solve the problem ?

public partial class copyparallel : Form
        IApplication papp;
        public IHookHelper phookhelper;
         IPolycurve ppolycurve;

        public copyparallel()

        private void button1_Click(object sender, EventArgs e)

            IFeatureLayer pfeaturelayer;
            IFeatureClass pfc;

            pfeaturelayer = (IFeatureLayer) phookhelper.FocusMap.get_Layer(0);
           pfc = pfeaturelayer.FeatureClass;

           IConstructCurve construct = new PolylineClass();
           object offset = esriConstructOffsetEnum.esriConstructOffsetMitered;

           object missing = Type.Missing;
           construct.ConstructOffset(pfeaturelayer as IPolyline, 100.3 , missing,missing);

           IFeatureClass poutfc;
           IFeature newf = pfc.CreateFeature();
           newf.Shape = (IGeometry)construct;



1 Answer 1


You'll have to loop through each feature in the feature class to get a polyline instead of trying to cast the entire featurelayer to a polyline.

*To answer your comment, it would look something like this. You'll have to translate into C#

Dim pFCur As IFeatureCursor
Dim pFeat As IFeature

pFCur = pfc.Search(Nothing, False)
pFeat = pFCur.NextFeature
Do Until pFeat Is Nothing
    Dim pPolyline As IPolyline
    pPolyline = pFeat.ShapeCopy

    'your code to construct the offset

    pFeat = pFCur.NextFeature

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.