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.


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_WGS19 84)

.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 = pFields

pField = New Field

pfieldEdit = pField

With pfieldEdit

.Name_2 = "SHAPE"

.Type_2 = esriFieldType.esriFieldTypeGeometry

.GeometryDef_2 = pGeomDef

End With


Dim pWorkSpaceFactory As IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory

Dim pFWS As IFeatureWorkspace = pWorkSpaceFactory.OpenFromFile("c:\Dan\Data\DataFi tness-1AOI.mdb", 0)

Dim pFeatClass As IFeatureClass

Dim pUID As New ESRI.ArcGIS.esriSystem.UID

pUID.Value = "esriGeoDatabase.Feature"


pFeatClass = pFWS.CreateFeatureClass("TestFC1", pFieldsEdit, pUID, Nothing, esriFeatureType.esriFTSimple, "SHAPE", "")


Not sure if that's the cause of the problem, but singleton classes (SpatialReferenceEnvironment and AccessWorkspaceFactory) should not be created directly, but through Activator.CreateInstance calls.

Anyway, I have also encountered LoaderLocks in the past, but have never been able to get to the root of the problem. I believe it has to do with the order libraries are loaded in, and it usually occured when working with WinForms at some point.

I usually disabled the LoaderLock MDA (debugging assistant) in VS debugger settings. This does not seem to cause any other problems, at least I didn't experience any.

  • Thanks, but that didn't help my situation. – user1591 Jan 14 '11 at 16:14

The problem as been solved. I was not defining the XY domain of the spatial reference for the geometry field.


Try this in place of your last (failing) line:

pFeatClass = pFWS.CreateFeatureClass("TestFC1", pFields, Nothing, Nothing, esriFeatureType.esriFTSimple, "SHAPE", String.Empty)
  • Thanks, but no such luck. It still behaves the same way after making the suggested change. – user1591 Jan 14 '11 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy