Wierd rpc_e_disconnected error

Hey everybody,

Today I've start getting rpc_e_disconnected "The object invoked has disconnected from its clients" errors for some reason.

After exhausting tests which was very hard I found this lines of code in my AddIn that adds flat view from SheetMetal body:

Dim BodiesIn(0) As DispatchWrapper
BodiesIn(0) = New DispatchWrapper(bodies(0))
Dim flatView As View = draw.CreateFlatPatternViewFromModelView3(model.GetPathName, model.GetActiveConfiguration.name, 0.14, 0.14, 0, False, False)
If Not IsNothing(flatView) Then flatView.Bodies = BodiesIn(0)

This code cause for some reason to this line:

feat = feat.GetNextFeature

Popup the error rpc_e_disconnected.

I did some very uggly workaround to solve it for now:

            Try
                feat = feat.GetNextFeature
            Catch
                If tModel.GetType = swDocumentTypes_e.swDocASSEMBLY Then
                    Dim doc As AssemblyDoc = tModel
                    feat = doc.FeatureByName(featureName)
                    feat = feat.GetNextFeature
                ElseIf tModel.GetType = swDocumentTypes_e.swDocPART Then
                    Dim doc As PartDoc = tModel
                    feat = doc.FeatureByName(featureName)
                    feat = feat.GetNextFeature
                End If
            End Try

This line is in a while loop which calls to other functions (includes the function that creates the FlatView). After calling to my other function which includes the feature as a parameter ByRef but doesn't change it at all, only read info from it.

If someone could help me to understand this issue I will be glad. I am pretty sure that the workaround is very bad.

Thanks,

Bnaya Livne

SolidworksApi macros