LokionNitrox

IFeatureWorkspace.CreateFeatureClass() error (C#)

Discussion created by LokionNitrox on Mar 10, 2011
Latest reply on Apr 1, 2011 by LokionNitrox
I'm trying to read a csv file straight into a set of new featurce classes within a new file geodatabase (or a shapefileworkspacefactory, for now) but I am getting the following stack trace error 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


I had initially believed it was related to the shared lock on the FGDB, but after testing it against the ShapefileWorkspaceFactory with the same results I'm now completely baffled.  I've been fighting this issue for way too long now and it's holding my project up.  I've also attempted to place a COMReleaser() on the workspace, but that just creates a situation where the reference persists but the object is garbage collected.  Relevant sections of code are below, any advice is greatly appreciated:

        public static IFeatureWorkspace CreateWorkspace(String path, String jobnumber)
        {
            //Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
            //IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            //workspaceFactory.Create(path, jobnumber, null, 0);
            //IWorkspace workspace = workspaceFactory.OpenFromFile(path + jobnumber + ".gdb", 0);
            ShapefileWorkspaceFactory ws = new ShapefileWorkspaceFactory();
            String outpath = path + jobnumber;
            System.IO.Directory.CreateDirectory(outpath);
            IFeatureWorkspace workspace = (IFeatureWorkspace)ws.OpenFromFile(outpath,0);
            return workspace;
        }
...
...
            var CLSID = new UIDClass();
            CLSID.Value = "esriGeodatabase.Feature";
            IFields outfields = CreateFields();
 
            try
            {
                IFieldChecker fieldchecker = new FieldCheckerClass();
                IEnumFieldError enumfielderror = null;
                IFields validatedFields = null;
                fieldchecker.ValidateWorkspace = (IWorkspace)workspace;
                fieldchecker.Validate(outfields, out enumfielderror, out validatedFields);
                workspace.CreateFeatureClass("test.shp", outfields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            }
            catch (Exception exc)
            {
                throw new Exception(String.Format("Error {0}", exc.Message));
            }

Outcomes