16 Replies Latest reply on Feb 18, 2014 12:30 PM by Krishna Regmi

    ?The object invoked has disconnected from its clients?.

      We have a Add-In module build with Visual Basic .Net 2008, and are using it with SW 2009 64bit on WinXP 64 bit.

      Our users keep getting the "The object invoked has disconnected from its clients?. (?Exception from ?HRESULT?: ?0?x?80010108 ?(?RPC_E_DISCONNECTED?))" error.

      It is hard to pin down because it does not occur all the time and does not occur in the same spot in the code. It appears to happen randomly.

      Is there any way to prevent this from happening?
      Is there any way to detect this situation?
      Is there any way to recover once this happens in the application?

      Below is some example code that sometimes produces the error(not always).

      Public Function RenameComp(ByVal OldName As String, ByVal NewName As String, Optional ByVal SWApplication As SldWorks.SldWorks = Nothing) As String
      Try
      If IsNothing(SWApplication) = True Then SWApplication = SWApp
      'select the comp by its old name
      Dim swModel As SldWorks.ModelDoc2
      swModel = SWApp.IActiveDoc2
      If swModel Is Nothing Then
      Throw New Exception("Active document is nothing. Cannot select cabinet")
      End If
      Dim cname(0) As String
      cname(0) = OldName
      SelectComponents(cname, False, SWApp)
      Dim SelMgr As SldWorks.SelectionMgr
      SelMgr = swModel.SelectionManager()
      Dim SelComp As SldWorks.Component2 = SelMgr.GetSelectedObject6(1, -1)
      If SelComp Is Nothing Then
      Dim this As New Exception("Could Not Select Cabinet")
      Throw this
      End If
      'Change the name to the new name
      SWApp.SetUserPreferenceToggle(SwConst.swUserPreferenceToggle_e.swExtRefUpdateCompNames, False)
      SelComp.Name2 = NewName
      Return SelComp.Name2
      Catch ex As Exception

      Throw New Exception("Failed RenameComp. OldName[" & OldName & "] NewName[" & NewName & "]" & ex.Message)

      End Try
      End Function
        • ?The object invoked has disconnected from its clients?.
          Luke Malpass
          What line does the error occur at?

          The RPC Disconnected error means that the pointer to the COM object is no longer valid, usually a ModelDoc2 object that no longer exists (model closed) or a SolidWorks variable that has been lost (SolidWorks closed or error in SolidWorks COM functionality, try re-installing SW).
            • ?The object invoked has disconnected from its clients?.
              I'm not sure if it occurs on any one line or not, since I can't replicate the problem on demand.

              The problem occurs on all our workstations, and all those were just recently built, so I don't think a reinstall would help.

              I'm not familiar with the inner workings of COM. Are there any 'gotchas' or things I could check my code for to prevent COM related problems?
              • Re: ?The object invoked has disconnected from its clients?.

                Hi there,

                 

                I'm getting the same RPC_E_DISCONNECTED error in my add-in and in my stand-alone app. It's seems to be occuring randomly, yet I'm sometimes able predict when it's going to happen as if it was occuring periodically. Let me give you all the details:

                 

                The error is thrown exactly while processing the code line comprising the Face2::GetTessTriangles method. Calls to SW objects before, or even after, the faulty code line work fine. Basically, what I'm trying to do, it's getting a body's bounding box with good precision, what the various GetBox methods from the API can't do.

                 

                Here's the funny part. If I change the image quality (SldWorks::SetTesselationQuality) from fine (90) to coarse (10), the error still occurs, but less frequently. Also, given a constant image quality index, complex parts (large number of complex faces) won't be processed at all, whereas simpler parts willfail systematically 1 time out of 2, and even more simpler parts (prismatic with holes) will fail systematically 1 time out of 4.

                 

                This behaviour have been reproduced on at least three different computer, all working on Windows XP 32bit and with SW 2009 Sp3 freshly installed. I'm coding in VB .NET with Visual Studio 2005. It's occuring with the release version of my add-in, not while debugging.

                 

                The issue doesn't have exactly the same behaviour weather I'm running the add-in or the .exe. With the add-in, the part's processing just fails and SW remains open. With the .exe (batch program) though, SW crashes and SW Rx is launch.

                 

                The thing is that I need the body tesselation and the fastest way to get it is through the graphic display tesselation with a custom image quality index. I've used the SW Tesselation object before, but it slows down my .exe real bad.

                 

                So what could be the problem? My take is that SW API is not that robust, and the COM connexion is somewhat lost for memory or timeout reasons. But since I'm no COM or for that matter SW API expert, I'm reaching to you guys to find a glimpse of light on this cloudy mess.

                 

                Thanks a lot!

                 

                Antoine

                  • Re: ?The object invoked has disconnected from its clients?.
                    Rajat Jain

                    Antoine,

                     

                    I have had the same problem some time back and I attributed it to SolidWorks API itself. Later, I found that the problem was in my code itself. This issue occurs when we do some operation on the body such that the faces get refreshed and hence the Face object itself does not point to the correct value. I have the following suggestions: -

                    1. When you traverse faces of a body and generate tesselations, do not perform any operation on the body such that the faces can get refreshed. Instead, you can select the face and perform the operation outside the loop.
                    2. Use safeEntity object to get the corresponding entuty from the face and use this entity to generate back the face object wherever required. This ensures that you have the correct face object even if the body is refreshed.

                    In addition, you should always call Face2::getTesselationCount() before calling Face2::getTesselations().

                     

                    Hope this helps!!!

                     

                    Rajat Jain

                    • Re: ?The object invoked has disconnected from its clients?.
                      Luke Malpass

                      That error is always because the com pointer is pointing to a disposed object, so you need to make sure you have the correct pointer. The line it fails at is usually containing the invalid com pointer, but not always.

                       

                      This can rarely happen when SolidWorks API fails internally usually due to a bad installation, and you get a RPC_DISCONNECTED error on the SldWorks.SldWorks object itself.

                       

                      Not much you can do other than make sure you are coding correctly and creating/disposing of the com objects correctly as you go.

                    • Re: ?The object invoked has disconnected from its clients?.
                      Pooja Sahay

                      Hi Luke,

                       

                      I have also faced a similar problem. I have a .exe file which is to be executed. During this process, SolidWorks has to be kept open.

                      If not an "Automation Error:...." occurs and then the error description states that "The remote server is not available."

                       

                      If I keep a SolidWorks file open, then my Macro works fine. But when I close the SolidWorks File I get a "Click Ok to Terminate......<Error Description>".

                      My work is not affecte, but this error occurs.

                       

                      Can you guide me on this ?

                       

                      Thanks in advance

                    • Re: ?The object invoked has disconnected from its clients?.
                      Stefan Wozniak

                      If you use default template your addin is switching modeldoc2 when you change opened doc. So if your module is using same modelDoc2 as addin.Your modelDoc2 will be disconected each time you change active doc. It's only an idea, but you can look on it.

                      In program nothing is random ;>