Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
    
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? –  MathiasWestin Mar 10 '11 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 '11 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 '11 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 '11 at 15:33

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.