a.colby@helyx.co.uk

IMap.AddLayer error at 10

Discussion created by a.colby@helyx.co.uk on Apr 27, 2011
Latest reply on May 3, 2011 by amay_uk
I am trying to add a layer to the current active view by using the IMap.AddLayer method using the code below:

  Dim currentMap As IMap = CType(m_application.Document, IMxDocument).ActiveView.FocusMap
  Dim workspace As IWorkspace2 = OpenFileGDB(gdbPath, gdbName)
  Dim featWorkspace As IFeatureWorkspace = CType(workspace, IFeatureWorkspace)

  For i As Integer = 0 To featureClassNames.GetUpperBound(0)

        Dim featLayer As IFeatureLayer = New FeatureLayerClass
        featLayer.FeatureClass = featWorkspace.OpenFeatureClass(featureClassNames(i))

        Dim layer As ILayer = CType(featLayer, ILayer)
        layer.Name = featLayer.FeatureClass.AliasName

        currentMap.AddLayer(featLayer)
  Next

However, when I run the code I get the following error:

Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)

I've noticed that if I ignore the exception by putting it inside a Try...Catch...End Try then the layer is created but not always shown (if I save the MxD and then re-open it is appears) and ArcMap starts to fallover.

I should also say that I am running this code in a custom extension that generates a number of processing threads to perform some background data conversion.  This error is only generated/experienced then the additional threads are running (using System.Threading.Thread to generate and start the threads).

Anyone else experienced this and have an idea of what is causing the issue?

Running ArcInfo 10 (with service pack 1).

Thanks,

Tony

Outcomes