I create a personal geodatabase and then a FeatureClass in that gdb to store the results of an analysis. When I call <FeatureClass>.CreateFeature() I get an exception message "Item not found in this collection." I've ensured my fields are set correctly, I physically open the .mdb and the table looks correct. Here's my code (I'm using properties from an existing SDE featureclass (pipeFittingFeatureClass) to construct the new FeatureClass):
//create the 'ServicePointCount' field
IFieldEdit servicePointCountFieldEdit = new FieldClass();
servicePointCountFieldEdit.Name_2 = "ServicePointCount";
servicePointCountFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
//create ORIG_OID field
IFieldEdit origOIDFieldEdit = new FieldClass();
origOIDFieldEdit.Name_2 = "ORIG_OID";
origOIDFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
//create OID field
IFieldEdit OIDFieldEdit = new FieldClass();
OIDFieldEdit.Name_2 = "ObjectID";
OIDFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
//create shape field
IFieldEdit shapeFieldEdit = new FieldClass();
shapeFieldEdit.Name_2 = this.pipeFittingFeatureClass.ShapeFieldName;
shapeFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
IGeometryDef shapeFieldGeometryDefinition = new GeometryDefClass();
IGeometryDefEdit shapeFieldGeometryDefinitionEdit = (IGeometryDefEdit)shapeFieldGeometryDefinition;
shapeFieldGeometryDefinitionEdit.GeometryType_2 = this.pipeFittingFeatureClass.ShapeType;
ISpatialReferenceFactory3 spatialRefFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference origRef = this.pipeFittingFeatureClass.Fields.get_Field(this.pipeFittingFeatureClass.Fields.FindField("SHAPE")).GeometryDef.SpatialReference;
shapeFieldGeometryDefinitionEdit.SpatialReference_2 = spatialRefFactory.ConstructHighPrecisionSpatialReference(origRef, -1, 0, 0);
shapeFieldEdit.GeometryDef_2 = shapeFieldGeometryDefinitionEdit;
//create new fields class
IFieldsEdit fieldsEdit = new FieldsClass();
fieldsEdit.FieldCount_2 = 4;//this.pipeFittingFeatureClass.Fields.FieldCount + 2;
fieldsEdit.set_Field(0, (IField)OIDFieldEdit);
fieldsEdit.set_Field(1, (IField)origOIDFieldEdit);
fieldsEdit.set_Field(2, (IField)servicePointCountFieldEdit);
fieldsEdit.set_Field(3, (IField)shapeFieldEdit);
//create the featureclass
IFeatureClass EFVValvesFeatureClass = workspace.CreateFeatureClass("EFVValves", (IFields)fieldsEdit, null,
null, this.pipeFittingFeatureClass.FeatureType, this.pipeFittingFeatureClass.ShapeFieldName, "");
//THIS THROWS THE "Item not found in this collection." EXCEPTION
IFeature newFeature = EFVValvesFeatureClass.CreateFeature();
I tried searching for this error and got a few hits but none of the fixes applied to my situation so I am at a loss as to ideas. My suspicion is the how I define the Shape field, but if I do not create a high precision spatial reference (the template spatial reference I use is low), it won't even allow me to create the featureclass.For reference, I'm using ArcGIS 9.3.1 Sp1, and this is just a small console app that does some custom tracing and stores the results in this personal GDB.