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.

  • I had some issues that where solved by making sure that garbage collection don't remove objects that are sharing state between COM object. You could try making some of the variables static and release those after you finishing the whole operation? Mar 10, 2011 at 20:06
  • Thanks Mathias. I've actually got CreateFileGDBWorkspace() set as a static method now, but it's giving me the same respone. I went so far as to "slum it" and tried creating a shapefileworkspacefactory but got the same results, I got as far as throwing a COMException yesterday but I was trying to rule out the chance that I was passing invalid fields (using IFieldChecker)
    – Luke
    Mar 11, 2011 at 13:26
  • UPDATE: I'm building the geodatabase in a background thread now, and when I reclaim that thread I am without a lock on the geodatabase, however I'm still having the issue when I use the wsfactory to open the gdb so that I can create the new fc's
    – Luke
    Mar 23, 2011 at 14:33
  • UPDATE: It's looking like there is a flaw in the .NET framework around the IList<T> and ICollection<T> that causes the excption in my case. I was able to create a workflow with python that takes care of the data creation and import. The only hitch is that you have to call the python script as a new Process() from within the application. email me if you are interested in the code/ workaround. good luck
    – Luke
    Mar 30, 2011 at 15:33
  • @Luke: Could you describe how IList<T> and ICollection<T> supposedly lead to your issue? While I believe it highly unlikely that these .NET Framework interfaces or the implementing classes are broken in any way (since they are so crucial and thus very well-tested), if indeed they cause problems during COM interop, it would be extremely helpful to know about it!
    – stakx
    Sep 2, 2014 at 6:00

1 Answer 1


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.

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.