Unable To Cast COM Object Of Type 'System.__ComObject' To Interface Type 'System.Runtime.InteropServices.ComTypes.IConnectionPointContainer'

Resolution when it is not possible to cast COM object of type 'System.__ComObject' to interface type "System.Runtime.InteropServices.ComTypes.IConnectionPointContainer."

  1. Try to understand the process and use case.
  2. Isolate the Excel file and verify whether the Excel Application Scope is present inside the scope of a loop.
  3. Add the Close workbook activity in each iteration.
  4. Call the garbage collectors explicitly in the code in the places where the crash was encountered and also at the end of the code
    • Use Invoke Method activity - Set target type as - System.GC, Use Method Name - Collect
    • Use Invoke Method activity - Set target type as - System.GC, Use Method Name - WaitForPendingFinalizers
    • Use Invoke Method activity - Set target type as - System.GC, Use Method Name - Collect
If the above does not help:
  • Add the Kill process activity (User level) in each iteration and reopen the Excel in the next iteration.
  • Add a delay of 1-2 seconds right after the Excel Application Scope