none
System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used RRS feed

  • General discussion

  • Getting the following exception for DirectoryEntry.Rename(..) in multi-threaded request.

    System.Runtime.InteropServices.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.
       at System.StubHelpers.StubHelpers.InternalGetCOMHRExceptionObject(Int32 hr, IntPtr pCPCMD, Object pThis, Boolean fForWinRT)
       at System.StubHelpers.StubHelpers.GetCOMHRExceptionObject(Int32 hr, IntPtr pCPCMD, Object pThis)
       at System.DirectoryServices.Interop.UnsafeNativeMethods.IAdsContainer.MoveHere(String sourceName, String newName)
       at System.DirectoryServices.DirectoryEntry.MoveTo(DirectoryEntry newParent, String newName)
       at System.DirectoryServices.DirectoryEntry.Rename(String newName)

    Tried by implementing the IDisposable interface as suggested by MSDN but the problem still persists. In non-threaded requests it works fine.

    Thursday, December 22, 2016 11:00 AM

All replies

  • Hi Manjunath007,

    >>Getting the following exception for DirectoryEntry.Rename(..) in multi-threaded request.

    It sounds like you may be instantiating the COM object and then attempting to access it from another thread, perhaps in a Timer.Elapsed event. you need to instantiate the COM object within each thread you will be using it in

    COM object that has been separated from its underlying RCW cannot be used.

    Please also check the reply from Steve Sheldon , It should be give you some hints.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 23, 2016 8:02 AM