CreateFeatureClass failure in VB.net

420
4
01-13-2011 07:59 AM
DanielFrye
New Contributor
I'm using ArcGIS 9.3.1 and trying to get the code to create a new feature class in an existing personal geodabase to work but I am having no luck.  When running in debug mode from within vb.net it will fail with the standard "LoaderLock" error where it tells you to not run managed code inside a DllMain.  I'm sure this is a simple problem that I'm just not seeing, but I've been searching the forums for a couple of days not with no luck.  If anyone has insight after looking at the code below I would be very thankful.

Dan


        Dim pGeomDef As IGeometryDef = New GeometryDef
        Dim pGeomDefEdit As IGeometryDefEdit = CType(pGeomDef, IGeometryDefEdit)

        With pGeomDefEdit
            .GeometryType_2 = esriGeometryType.esriGeometryPolygon
            Dim pSpatRefFact As ISpatialReferenceFactory2 = New ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment
            Dim pGeoCoordSys As IGeographicCoordinateSystem = pSpatRefFact.CreateGeographicCoordinateSystem(ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984)
            .SpatialReference_2 = pGeoCoordSys
        End With

        Dim pFields As IFields = New Fields
        Dim pFieldsEdit As IFieldsEdit
        Dim pField As IField
        Dim pfieldEdit As IFieldEdit

        pFieldsEdit = pFields
        pField = New Field
        pfieldEdit = pField

        With pfieldEdit
            .Name_2 = "ObjectID"
            .Type_2 = esriFieldType.esriFieldTypeOID
        End With
        pFieldsEdit.AddField(pField)

        pFieldsEdit = pFields
        pField = New Field
        pfieldEdit = pField
        With pfieldEdit
            .Name_2 = "SHAPE"
            .Type_2 = esriFieldType.esriFieldTypeGeometry
            .GeometryDef_2 = pGeomDef
        End With
        pFieldsEdit.AddField(pField)

        Dim pWorkSpaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
        Dim pFWS As IFeatureWorkspace = pWorkSpaceFactory.OpenFromFile("c:\Dan\Data\DataFitness-1AOI.mdb", 0)

        Dim pFeatClass As IFeatureClass
        Dim pUID As New ESRI.ArcGIS.esriSystem.UID
        pUID.Value = "esriGeoDatabase.Feature"

        'FAILING HERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        pFeatClass = pFWS.CreateFeatureClass("TestFC1", pFieldsEdit, pUID, Nothing, esriFeatureType.esriFTSimple, "SHAPE", "")
0 Kudos
4 Replies
SteveFang
New Contributor III
You code looks fine from a initial glance.  However, I noticed you have a space in your geodatabase.  Not sure if it's intentional.  You really don't need the second PFieldsEdit = PFields.  Other than that, I can't see anything wrong.
0 Kudos
DanielFrye
New Contributor
That extra space in the workspace path is just a mistake from when I pasted the code here.

Interestingly, if I change these two lines to create a shapefile rather than a feature class in a geodatabase it works just fine without making any chages to the CreateFeatureClass line.

ORIGINAL CODE
---------------
Dim pWorkSpaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
Dim pFWS As IFeatureWorkspace = pWorkSpaceFactory.OpenFromFile("c:\Dan\Data\DataFi tness-1AOI.mdb", 0)

NEW CODE
----------
Dim pWorkSpaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory
Dim pFWS As IFeatureWorkspace = pWorkSpaceFactory.OpenFromFile("c:\Dan\Data\", 0)
0 Kudos
DanielFrye
New Contributor
I've figured out that the problem was due to the fact that I was not defining the XY domain of the spatial reference for the geometry field.  All is working now.
0 Kudos
LukeBadgerow
New Contributor
How was your code failing?

my stack trace is coming back with something what looks like a schema lock issue, but I'm not setting the XY Domain currently either (partly because I don't necessarily know what it's going to be prior to creation)


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.
0 Kudos