I have a polyline and I want to convert it to a single polygon feature, I used this code but I get error while I can convert the same shapefile using feature to polygon on ArcGIS. Where is my mistake?

ESRI.ArcGIS.DataManagementTools.FeatureToPolygon ftp = new ESRI.ArcGIS.DataManagementTools.FeatureToPolygon(path + "lines.shp", path + "polygons.shp");
        ftp.attributes = "NO_ATTRIBUTES";
        GP.Execute(ftp, null);

The path is set to

string path= System.IO.Path.GetDirectoryName(Application.ExecutablePath) + @"\temp\Conversations\";

and the error that raises is:

Error HRESULT E_FAIL has been returned from a call to a COM component.

I tried to change output path to

"E:/MASTER/Project/Semirom/file gis semirom/New Folder/gisiran.gdb/tester"

But I get the same error... Do you think I must set Environment workspace or something like that? I also use:

ESRI.ArcGIS.ConversionTools.GPXtoFeatures and ESRI.ArcGIS.DataManagementTools.PointsToLine(path + "points.shp", path + "lines.shp"); with the same settings and they works fine..:(

Is there any better approach to create a polygon?

  • 1
    Please edit the question to include the version of ArcGIS and the exact error you have received.
    – Vince
    Jul 11, 2014 at 9:48
  • 1
    Also what are you variables path set to?
    – Hornbydd
    Jul 11, 2014 at 10:21
  • @Vince I added error and I am using arcmap 10.2.1 and arcEngine as the same version
    – Majid
    Jul 11, 2014 at 11:50
  • @Hornbydd I added the path to my post
    – Majid
    Jul 11, 2014 at 11:50
  • I also tried this function using arcpy and If worked fine but I cant run it with C# with the same parameters that I used in arcpy
    – Majid
    Jul 12, 2014 at 21:08

2 Answers 2


try this

using ESRI.ArcGIS.DataManagementTools;

FeatureToPolygon featureToPolygon = new FeatureToPolygon();

featureToPolygon.in_features = pInWorkspace.PathName + "\\" + pInFeatureClassName.FeatureDatasetName.Name + "\\Temp_Line_UnNamed";
featureToPolygon.out_feature_class = pInWorkspace.PathName + "\\" + pInFeatureClassName.FeatureDatasetName.Name + "\\Master_Poly_UnNamed";

featureToPolygon.attributes = "ATTRIBUTES";
featureToPolygon.cluster_tolerance = 0.01;
featureToPolygon.label_features = "";

RunTool(gp, featureToPolygon, null);

public static void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel tc)
    // set overwrite option to true
    geoprocessor.OverwriteOutput = true;

    // execute tool
         geoprocessor.Execute(process, null);
    catch (Exception err)

private static void ReturnMessages(Geoprocessor gp)
    if (gp.MessageCount > 0)
        for (int i = 0; i <= gp.MessageCount - 1; i++)


static void Main()
    Application.Run(new frmHydroLinesToPolygons());

private void frmHydroLinesToPolygons_Load(object sender, EventArgs e)
    bool bLicenseAvailable;

    // initializes ArcObjects components runtime environment.
    // This class must be first Arcobject created 
    IAoInitialize aoInitialize = new AoInitializeClass();
    esriLicenseStatus status;

    // checks for ArcInfo License - essential when converting feature to polygons 
    status = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); //.esriLicenseProductCodeArcInfo); //.esriLicenseProductCodeArcView);

    // check if license is available
    if ((status == esriLicenseStatus.esriLicenseAvailable) || (status == esriLicenseStatus.esriLicenseAlreadyInitialized) || (status == esriLicenseStatus.esriLicenseCheckedOut))
        bLicenseAvailable = true;
        bLicenseAvailable = false;

    // if not licensed - initialize license
    if (bLicenseAvailable != true)
        if (status == esriLicenseStatus.esriLicenseNotLicensed)
            MessageBox.Show("Sorry... An ArcInfo License is Required for this Program");
  • thanks for your help but I get this error:Failed to execute. Parameters are not valid. ERROR 000824: The tool is not licensed. Failed to execute (FeatureToPolygon).I have ArcInfo licence on my pc and FeatureToPolygon works fine on ArcMap but I get this error,I tried to initiate advanced licence in programs runtime but got no chance
    – Majid
    Jul 14, 2014 at 17:45
  • Have you tried to license the required extension to use this tool? not only the arcmap, this is done in the app that you are developing
    – XtianGIS
    Jul 14, 2014 at 18:43
  • I had added this before your edit but there is not any chance to work and that error comes.. status = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced); //.esriLicenseProductCodeArcInfo); //.esriLicenseProductCodeArcView);..anyway I find another way to creat polygons from points and I think it works..Now I want to show the result in map view Can you suggest me the best way to show a Ipolygon feature to mapView?without saveing it on disk or sth like that?
    – Majid
    Jul 15, 2014 at 10:42
  • Sorry.. Cant help you on the mapview
    – Deke
    Jul 15, 2014 at 11:33
  • @XtianGIS Yes,I have tried spatial analize and 3d analise before using this tool
    – Majid
    Jul 15, 2014 at 14:27

You require to check out the licenses of the extensions required:


When using an ArcView or ArcEditor license, a program must explicitly use AoIntialize, and the product must be set to ArcView or ArcEditor, or the program fails. By default, the geoprocessor always assumes an ArcInfo license is required for execution of a script; therefore, if a program does not explicitly set the product required by the tools it executes, an ArcInfo license is initialized. See the following code example:

check this example:

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.esriSystem;

static void Main(string[] args)

  //Initialize the application.
  esriLicenseStatus licenseStatus = esriLicenseStatus.esriLicenseUnavailable;
  IAoInitialize m_AoInitialize = new AoInitializeClass();
  licenseStatus = m_AoInitialize.Initialize
  licenseStatus = m_AoInitialize.CheckOutExtension

  // Initialize the geoprocessor.         
  Geoprocessor gp = new Geoprocessor();
  Slope tSlope = new Slope();
  tSlope.in_raster = @"E:\Data\demlatgrd";
  tSlope.out_raster = @� � �E:  \
    Data  \
    aspect03 ";gp.Execute(tSlope, null);

  licenseStatus = m_AoInitialize.CheckInExtension
  m_AoInitialize = null;


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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