Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
when trying to add an index to a feature class
the error happens at the last line befor the return statment. please help
protected bool CreateIndex( IFeatureClass featClass, params object[] fieldsNames)
{
IFields pFields = new Fields();
IField pField;
IFieldsEdit pFieldsEdit;
pFieldsEdit = (IFieldsEdit)pFields;
pFieldsEdit.FieldCount_2 = fieldsNames.Length + 1;
int h;
string indexName="";
for (int i = 0; i < fieldsNames.Length; i++)
{
h = featClass.FindField(fieldsNames.ToString());
// pField = featClass.Fields.get_Field(h);
pFieldsEdit.set_Field(i, featClass.Fields.get_Field(h));
pField = null;
indexName = indexName + ((i == 0) ? fieldsNames.ToString() : "," + fieldsNames.ToString());
}
IIndex pIndex= new Index();
IIndexEdit pIndexEdit =(IIndexEdit) pIndex;
pIndexEdit.Fields_2 = pFields;
pIndexEdit.Name_2 = indexName;
featClass.AddIndex(pIndex); //this the line where the error takes place
return true;
}