What is this exception?

I get this exception by reading forms in an excel sheet in C #: on a line of code

if (worksheet.Shapes.Count >= iCurrentRowIndex)
{ }

Cannot start COM object of type 'System .__ ComObject' for interface type 'Microsoft.Office.Interop.Excel._Worksheet. This operation failed because the QueryInterface query on the COM component for the interface with IID '{000208D8-0000-0000-C000-000000000046} failed due to the following error: the application is called an interface that was created for another topic. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).

Edited by:

This application works fine locally, but when I deploy it to IIS, it throws an exception. What is the reason? I use code for the stream as

string strImageSavedPath = string.Empty;
ThreadStart cbThreadStater = delegate { strImageSavedPath =  CopyToClipBoard(worksheet, (int)iRowindex, strApplicationPath); };
Thread thrd = new Thread(cbThreadStater);
thrd.SetApartmentState(ApartmentState.STA);
thrd.Start();
thrd.Join(); 

CopyToClipBoard , .

System.InvalidCastException = " COM- " System.__ ComObject " 'Microsoft.Office.Interop.Excel._Worksheet. QueryInterface COM- IID '{000208D8-0000-0000-C000-000000000046}' - : , , . ( HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))." = "Microsoft.Office.Interop.Excel"
:         Microsoft.Office.Interop.Excel._Worksheet.get_Shapes()         KGD6ExcelReader.ExcelManager.CopyToClipBoard( , Int32 iRowindex, String strApplicationPath) D:\ParallelMinds\Shared\KGD6ExcelReader\KGD6ExcelReader\ExcelManager.cs: 522         KGD6ExcelReader.ExcelManager. < > c__DisplayClass3.b__0() D:\ParallelMinds\Shared\KGD6ExcelReader\KGD6ExcelReader\ExcelManager.cs: 376         System.Threading.ThreadHelper.ThreadStart_Context ( )         System.Threading.ExecutionContext.runTryCode(Object userData)         System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode , CleanoutCode backoutCode, Object userData)         System.Threading.ExecutionContext.RunInternal(ExecutionContext executeContext, ContextCallback, )         System.Threading.ExecutionContext.Run(ExecutionContext executeContext, ContextCallback, )         System.Threading.ThreadHelper.ThreadStart() InnerException:

+3
3

? , ApartmentState STA - SetApartmentState.

.

+1

COM (, ), , - -, . . .

.

+1

Source: https://habr.com/ru/post/1744938/


All Articles