Hi @loginerror, thanks for your reply.
I realized the issue I am facing should be on a separate thread since the process does not involve executing macro within an Excel application scope. However the exception encountered is quite similar. The process involves reading some data using Read Range into datatables from two Excel files. The exception occurs very randomly and if it happens, it’s always at the second Excel application scope.
![UiPath%20InvalidCastException](https://global.discourse-cdn.com/uipath/original/3X/3/b/3b486f95861794d1ca93f5268aaeb40e62cc06c6.jpeg)
Details:
18.4.2+Branch.master.Sha.9888b477be8d3ec8a832306fc59c34ba6edad108
Source: Excel application scope
Message: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘System.Runtime.InteropServices.ComTypes.IConnectionPointContainer’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{B196B284-BAB4-101A-B69C-00AA00341D07}’ failed due to the following error: The requested object does not exist. (Exception from HRESULT: 0x80010114).
Exception Type: System.InvalidCastException
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidCastException: Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘System.Runtime.InteropServices.ComTypes.IConnectionPointContainer’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{B196B284-BAB4-101A-B69C-00AA00341D07}’ failed due to the following error: The requested object does not exist. (Exception from HRESULT: 0x80010114).
at UiPath.Excel.WorkbookApplication…ctor(String workbookPath, String password, Boolean visible, Boolean autoSave, Boolean createNew, String editPassword, Boolean readOnly)
at UiPath.Excel.Activities.ExcelApplicationScope.Execute(NativeActivityContext context)
at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
I am using Community Edition.
Please find below the sample project. Note that the above error occurs very randomly. And if the above error doesn’t appear, there will be a Runtime execution error:
![Runtime%20execution%20error](https://global.discourse-cdn.com/uipath/original/3X/d/3/d38fdd0cf7bb1acb4fc093a1924dc3a894b09f08.jpeg)
TestForError.zip (38.8 KB)
Update: Unfortunately, when I open the sample project attached now, no errors will occur. The error can only be reproduced if I run the original project, but I can’t attach the original file and original Excel files as they contain sensitive data.