Shapefile created with addin attributes blank until exiting arcmap.  Help

01-29-2014 09:54 AM
New Contributor
I have created a shapefile using the code below.  The addin tosses no errors and the shapefiles show up in Arccatalog with the geography viewable in the preview window.  However if you preview the table the attribute items are listed but no attributes populated.  If I exit the arcmap with the add in low and behold the attributes get populated.  This code has worked before using vb and arcobjects from withing arcmap converting it to a ARCGIS addin now using  any suggestions

Public Sub ExportFc_Arc(ByVal txtType As String, ByVal txtAco As String)
        On Error GoTo ErrorHandler
        'Export selected Arc features to a new shapefile
        Dim pFLayer As IFeatureLayer
        Dim pFc As IFeatureClass
        Dim pInFeatureClassName As IFeatureClassName
        Dim pDataset As IDataset
        Dim pInDSName As IDatasetName
        Dim pFSel As IFeatureSelection
        Dim pSelSet As ISelectionSet
        Dim pFeatureClassName As IFeatureClassName
        Dim pOutDatasetName As IDatasetName
        Dim pWorkspaceName As IWorkspaceName
        Dim pExportOp As IExportOperation

        'Get the first layer in the map to be exported
        pdoc = My.ArcMap.Document
        pFLayer = pdoc.FocusMap.Layer(intArcLocation)
        pFc = pFLayer.FeatureClass

        'Get the Featureclassname from the featureclass
        pDataset = pFc
        pInFeatureClassName = pDataset.FullName
        pInDSName = pInFeatureClassName

        'Get the selected features
        pFSel = pFLayer
        pSelSet = pFSel.SelectionSet

        'Define the output featureclass
        'give it the name of the input feature class + exp
        pFeatureClassName = New FeatureClassName
        pOutDatasetName = pFeatureClassName
        pOutDatasetName.Name = txtType & "Arc" & "_" & txtAco
        pWorkspaceName = New WorkspaceName
        pWorkspaceName.PathName = "\\something\assessor\GIS\SegProgram"
        pWorkspaceName.WorkspaceFactoryProgID = "esriCore.shapefileworkspacefactory.1"
        pOutDatasetName.WorkspaceName = pWorkspaceName
        'Give the output shapefile the same props as the input dataset
        pFeatureClassName.FeatureType = pFc.FeatureType
        pFeatureClassName.ShapeType = pFc.ShapeType
        pFeatureClassName.ShapeFieldName = pFc.ShapeFieldName

        'Export selected features
        pExportOp = New ExportOperation
        pExportOp.ExportFeatureClass(pInDSName, Nothing, pSelSet, Nothing, pOutDatasetName, 0)
                Exit Sub
        MsgBox("ExportFC_Arc Routine: " & Err.Description)
    End Sub
0 Kudos
4 Replies
Regular Contributor III
You might need to release the COM objects you're using.  You can do that via Marshal.ReleaseComObject.
0 Kudos
New Contributor
You might need to release the COM objects you're using.  You can do that via Marshal.ReleaseComObject.

What com pbjects do you believe I should release.  I am now starting to release all of them in the procedure.  any hints please
0 Kudos
Regular Contributor III
I don't know the answer to that.  I would start by releasing them all to see if it fixes your problem.  If it does, and you decide you really don't want all those release calls then you can remove them one by one to see which are necessary and which aren't.
0 Kudos
MVP Frequent Contributor
An alternate approach is to call the existing Select geoprocessing tool, this will honor selections. Search the forum for IGeoProcessor to find out how to call existing geoprocessing tools from within VB .net.
0 Kudos