Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a batch geocoding application in ArcObjects/C# and keep getting the meaningless "Error HRESULT E_FAIL has been returned from a call to a COM component" error (error code -2147467259) and I can't figure out what's causing it. Any tips on how to figure out what the error is? I am running ArcGIS 9.3.1 SP 2. Below is the code that I have. I get the error on the last line, IRecordSet resultRecordSet = geocodeServer.GeocodeAddresses((IRecordSet)recordSetInit, addressProperties, null);

        IGeocodeServer geocodeServer = null;
        IGISServerConnection conn = null;
        conn = new GISServerConnection();
        IServerObjectManager som = conn.ServerObjectManager;

        IServerContext geocoderContext = som.CreateServerContext("StateCntyLoc", "GeocodeServer");
        geocodeServer = (IGeocodeServer)geocoderContext.ServerObject;
        IGeocodeServerObjects gom = (IGeocodeServerObjects)geocodeServer;

        IGeocodingProperties locProp = (IGeocodingProperties)gom.AddressLocator;
        locProp.SideOffset = 0;
        locProp.EndOffset = 0;

        IServerContext gdbContext = som.CreateServerContext("MF", "GeodataServer");
        IGeoDataServer geoDataServer = (IGeoDataServer)gdbContext.ServerObject;

        IGeoDataServerObjects gdsObjects = (IGeoDataServerObjects)geoDataServer;
        IWorkspace gdsWS = gdsObjects.DefaultWorkingWorkspace;
        IFeatureWorkspace featWS = (IFeatureWorkspace)gdsWS;

        ITable addressTable = featWS.OpenTable("FACT_CRASH_INPUT");
        IFields fields = geocodeServer.GetAddressFields();

        // The Address Field Mapping is key = Locator Field Names and value = RecordSet Field Names
        IPropertySet addressProperties = (IPropertySet)gdbContext.CreateObject("esriSystem.PropertySet");
        addressProperties.SetProperty(fields.get_Field(0).Name, "INTERSECTION");
        addressProperties.SetProperty(fields.get_Field(1).Name, "CNTY_CD");
        IRecordSetInit recordSetInit = (IRecordSetInit)gdbContext.CreateObject("esriGeodatabase.RecordSet");
        recordSetInit.SetSourceTable(addressTable, null);

        IRecordSet resultRecordSet = geocodeServer.GeocodeAddresses((IRecordSet)recordSetInit, addressProperties, null);

Now if I put the table in a file geodatabase on my local machine and do the batch geocoding against ArcGS Online, I get back a record set.

        IAoInitialize ao = new AoInitialize();

        IGeocodeServer geocodeServer = null;
        IAGSServerConnection agsServerConnection = null;

        IPropertySet connectionProperties = new PropertySet();
        connectionProperties.SetProperty("Url", "");

        IAGSServerConnectionFactory serverConnectionFactory = new AGSServerConnectionFactory();
        agsServerConnection = serverConnectionFactory.Open(connectionProperties, 0);

        IAGSEnumServerObjectName serverObjectNames = agsServerConnection.ServerObjectNames;

        IName name;
        IAGSServerObject serverObject = null;
        IAGSServerObjectName serverObjectName = serverObjectNames.Next();
        while (serverObjectName != null)
            if (serverObjectName.Name == "Locators/TA_Address_NA" && serverObjectName.Type == "GeocodeServer")
                name = serverObjectName as IName;
                serverObject = name.Open() as IAGSServerObject;
                if (serverObject as IGeocodeServer != null)
                    geocodeServer = serverObject as IGeocodeServer;
            serverObjectName = serverObjectNames.Next();

        IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
        IWorkspace workspace = workspaceFactory.OpenFromFile(@"C:\Users\marni\Desktop\TestGC.gdb", 0);
        IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
        ITable addressTable = featureWorkspace.OpenTable("FACT_CRASH_INPUT");
        IFields fields = geocodeServer.GetAddressFields();

        // The Address Field Mapping is key = Locator Field Names and value = RecordSet Field Names
        IPropertySet addressProperties = new PropertySet();
        addressProperties.SetProperty(fields.get_Field(0).Name, "INTERSECTION");
        addressProperties.SetProperty(fields.get_Field(1).Name, "CITY_CD");
        addressProperties.SetProperty(fields.get_Field(2).Name, "CNTY_CD");
        addressProperties.SetProperty(fields.get_Field(3).Name, DBNull.Value);
        IRecordSetInit recordSetInit = (IRecordSetInit)new RecordSet();
        recordSetInit.SetSourceTable(addressTable, null);

        IRecordSet resultRecordSet = geocodeServer.GeocodeAddresses((IRecordSet)recordSetInit, addressProperties, null);
share|improve this question
addressProperties has 2 props for the first code listing, but 4 in the second listing. Should it be that way? – Kirk Kuykendall Jul 12 '11 at 20:29
As @Kirk said - It looks to me like the field mapping is incorrect in the first example (compared to the second), which would cause a failure on the line that @mfowler specified. Field mapping issues are notorious for generic errors. – Radar Jul 12 '11 at 20:32
The first example is using my locator, which only has 2 fields. I have a locator that is using 4. I just tried it with that locator and got the same error. But I will double check my fields. The second example is using a predefined ArcGIS locator from As far as I know, our locators are functioning correctly - we use them on a daily basis. But I will try the first example using the locator from the second example to be thorough. – mfowler Jul 12 '11 at 20:55
In the first code snippet, you're not co-creating a Recordset object, while you're doing that in the second. Try creating it the same way in the first snippet. You're required to do that. Read this article from ESRI. – ujjwalesri Jul 13 '11 at 4:36
@ujjwalesri - Thanks for the link. I was able to compare what I was doing and I am doing the exact same thing. The only difference is my address table is an SDE table, not in a file geodatabase. In my examples, the second one works, its the first one that doesn't and that's the one I need to work because of the location of my input table. – mfowler Jul 13 '11 at 13:33

Your Answer


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

Browse other questions tagged or ask your own question.