Error: Not referencing Object - From Geoprocessing Tool VB.Net

Discussion created by keags1 on Nov 8, 2012
Latest reply on Nov 11, 2012 by keags1
Hi all,

I am in the process of writing a series of Geoprocessing Tools into an Add-In.
Basically the Add-In reads a Personal Database and then creates an XY Event and then overwrites a SHP file.

So far the tool works great, until it gets to the "CopyFeatures" part where it bombs and gives me an Error along the lines of an object is not being referenced.

I have run the full process manually through the ModelBuilder and it works.
I even exported the ModelBulder file to see the process and followed it to no avail.

Please if possible could someone look at my script and let me know where I can improve it.


        Dim gp As IGeoProcessor
        gp = New GeoProcessor

        Dim Tbl As String
        Dim X As String
        Dim Y As String
        Dim outL As String
        Dim CopyOut As String

        Tbl = txtArcmap & "\CAP2011VOCBIOB"
        X = "X"
        Y = "Y"
        outL = "CAP"

        Dim parameters As IVariantArray
        parameters = New VarArray


        gp.Execute("makexyeventlayer", parameters, Nothing)
        parameters = Nothing
        gp = Nothing

        ''Runs fine to here - I get a XY Event in my dataview
        ''now i want to make it permanent - so as per my modelbuilder run i use the CopyFeatures Tool

        gp = New GeoProcessor

            gp.OverwriteOutput = True
            gp.AddOutputsToMap = True

            outL = txtArcmap & "\CAP2011VOCBIOB_Features" ' Initially I used the "OutL = "CAP" but to no avail. So I checked the source of the XY Event and used it

            CopyOut = txtArcmap.Remove(txtArcmap.Length - 48) & "Shapefiles\CAP_BH1.shp" ' I want to overwrite the existing shp - even a new shp wont work

            MsgBox(CopyOut) 'reports the correct paths


            gp.Execute("CopyFeatures", parameters, Nothing)

        Catch ex As Exception
            MsgBox(ex.Message) ' Error states its not referenced to an object
        End Try