[GIS] IFeatureWorkspace.CreateFeatureClass() error

arcgis-10.0arcobjectscesri-geodatabase

I am trying to read a csv file straight into a set of new feature classes within a new file geodatabase, but I am getting the following stack trace when it fails:

Attempted to read or write protected
memory. This is often an indication
that other memory is corrupt.
ESRI.ArcGIS.Geodatabase at
ESRI.ArcGIS.Geodatabase.IFeatureDataset.CreateFeatureClass(String
Name, IFields Fields, UID CLSID, UID
EXTCLSID, esriFeatureType FeatureType,
String ShapeFieldName, String
ConfigKeyword) at
WaterEditorExtension.Model.SurveyUtilities.StreamWriting(String
pointtype, String outfile, String[]
record, IWorkspace workspace) in
C:\Documents and Settings\lbadgerow\My
Documents\Visual Studio
2008\Projects\WaterEditorExtension\WaterEditorExtension\Model\SurveyUtilities.cs:line
206.

I believe that it is related to a schema lock, but I am able to create a feature dataset which is confusing. (In proper stacktrace form, below is my workspace factory call, and my where I'm building the FC)

        public IWorkspace CreateFileGdbWorkspace(String path, String jobnumber)
        {
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);

            IWorkspaceName workspaceName = workspaceFactory.Create(path, jobnumber, null, 0);

            IName name = (IName)workspaceName;
            IWorkspace workspace = (IWorkspace)name.Open();
            return workspace;
        }
...
IFeatureWorkspace featwork = (IFeatureWorkspace)workspace;
featwork.CreateFeatureClass("test", outfields, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", "");

EDIT 17 March 2011: has anyone attempted to Thread a component (extension) of ArcMap? I'm thinking that I could release the schema lock that is preventing this from moving on to the FC creation phase of this project, but I can't seem to get ArcMap to remain stable when I create a new thread to build the gdb.

Best Answer

This error occur when the field count is not matched to created fields.

    Dim fields As IFields = New FieldsClass
    Dim fieldsEdit As IFieldsEdit = CType(fields, IFieldsEdit)
    fieldsEdit.FieldCount_2 = 2

    ' Create Object ID field.
    Dim fieldUserDefined As IField = New Field

    Dim fieldEdit As IFieldEdit = CType(fieldUserDefined, IFieldEdit)
    fieldEdit.Name_2 = "OBJECTID"
    fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID
    fieldsEdit.Field_2(0) = fieldUserDefined

    ' Create Shape field.
    fieldUserDefined = New Field
    fieldEdit = CType(fieldUserDefined, IFieldEdit)

    ' Set up geometry definition for the Shape field.
    ' You do not have to set the spatial reference, as it is inherited from the feature dataset.
    Dim geometryDef As IGeometryDef = New GeometryDefClass
    Dim geometryDefEdit As IGeometryDefEdit = CType(geometryDef, IGeometryDefEdit)

    ' By setting the grid size to 0, you are allowing ArcGIS to determine the appropriate grid sizes for the feature class. 
    ' If in a personal geodatabase, the grid size is 1,000. If in a file or ArcSDE geodatabase, the grid size
    ' is based on the initial loading or inserting of features.
    geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon
    geometryDefEdit.GridCount_2 = 1
    'geometryDefEdit.GridSize(0, 0)
    geometryDefEdit.HasM_2 = True
    geometryDefEdit.HasZ_2 = False
    ' Set standard field properties.
    fieldEdit.Name_2 = "SHAPE"
    fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry

    fieldEdit.GeometryDef_2 = geometryDef
    fieldEdit.IsNullable_2 = True
    fieldEdit.Required_2 = True
    fieldsEdit.Field_2(1) = fieldUserDefined

    ' Create a field of type double to hold some information for the features.
    fieldUserDefined = New Field

    fieldEdit = CType(fieldUserDefined, IFieldEdit)


    '----------------------------------------------------------------------------------------
    '--------------------------------- CREATE FEATURE CLASS------------------------------------------
    '----------------------------------------------------------------------------------------
    ' Create a feature class description object to use for specifying the CLSID and EXTCLSID.
    Dim fcDesc As IFeatureClassDescription = New FeatureClassDescriptionClass
    Dim ocDesc As IObjectClassDescription = CType(fcDesc, IObjectClassDescription)
    '-----------------------------------------------------------------------------
    Dim pWorkspaceFactory As IWorkspaceFactory = New SdeWorkspaceFactory

if fieldEdit.FieldCount is equal to a number greater than 2 , this error will occur.

Related Question