Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;


share|improve this question
up vote 4 down vote accepted

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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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