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

795
3
11-04-2013 07:39 AM
kju
by
New Contributor III
Post my code at first:
 #region Member.
        private AxMapControl _MapCon = null;    //MapControl from the main form.
        private IGeometry _BufferResult = null;
        #endregion
        public FrmBufferAnalyst(AxMapControl mapControl) {
            this._MapCon = mapControl;
            InitializeComponent();
        }
        private void FrmBufferAnalyst_Load(object sender, EventArgs e) {
            ShowSelectedFeatures();
        }
        /// <summary>
        /// //Show selected feature.
        /// </summary>
        void ShowSelectedFeatures() {
            lbox_selectedFeature.Items.Clear();
            ISelection fSelection = this._MapCon.Map.FeatureSelection;
            IEnumFeature enumF = (IEnumFeature)fSelection;
            IFeature f = null;
            while((f = enumF.Next()) != null) {
                lbox_selectedFeature.Items.Add("Feature layer:" + f.Class.AliasName);
                lbox_selectedFeature.Items.Add("OID:" + f.OID);
                lbox_selectedFeature.Items.Add("-----");    //Separator.
            }
        }

Before,I used the same project to execute buffer analyst,such as compute the area or query feature within the buffered feature.It works well.
But now,when I select the specifed feature and past them into another form and load.But it throws exception when trying to get the 'OID' property.Is something wrong with my code?Thanks.
0 Kudos
3 Replies
DuncanHornby
MVP Notable Contributor
If the error is occurring on the line:

lbox_selectedFeature.Items.Add("OID:" + f.OID);


Then it may be a type conversion error as OID will return an Integer. SO in VB I would do something like:

lbox_selectedFeature.Items.Add("OID:" + f.OID.ToString())
0 Kudos
kju
by
New Contributor III
If the error is occurring on the line:

lbox_selectedFeature.Items.Add("OID:" + f.OID);


Then it may be a type conversion error as OID will return an Integer. SO in VB I would do something like:

lbox_selectedFeature.Items.Add("OID:" + f.OID.ToString())

Thanks for your response but,It shouldn't that issue, 'f.OID' cencerns nothing with the exception.when debuging,'f' exsist but throws exception when get it's OID property.
0 Kudos
BruceNielsen
Occasional Contributor III
Does f.HasOID return True?
0 Kudos