title: What is this exception?
body: <p>I am getting this exception while reading the shapes in excel sheet in c#:
  on code line of</p>
  
  <pre><code>if (worksheet.Shapes.Count &gt;= iCurrentRowIndex)
  { }
  </code></pre>
  
  <blockquote>
    <p>Unable to cast COM object of type
    'System.__ComObject' to interface type
    'Microsoft.Office.Interop.Excel._Worksheet'.
    This operation failed because the
    QueryInterface call on the COM
    component for the interface with IID
    '{000208D8-0000-0000-C000-000000000046}'
    failed due to the following error: The
    application called an interface that
    was marshalled for a different thread.
    (Exception from HRESULT: 0x8001010E
    (RPC_E_WRONG_THREAD)).</p>
  </blockquote>
  
  <p>Edited:</p>
  
  <p>This application locally running perfect but when i deploy it on IIS , it throws exception. What should the reason? I use code for thread as </p>
  
  <pre><code>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(); 
  </code></pre>
  
  <p>Where <code>CopyToClipBoard</code> method reads the image of supplied row index, saves the image in file system and return the path.</p>
  
  <blockquote>
    <p>System.InvalidCastException was unhandled   Message="Unable to cast
    COM object of type 'System.__ComObject' to interface type
    'Microsoft.Office.Interop.Excel._Worksheet'. This operation failed
    because the QueryInterface call on the COM component for the interface
    with IID '{000208D8-0000-0000-C000-000000000046}' failed due to the
    following error: The application called an interface that was
    marshalled for a different thread. (Exception from HRESULT: 0x8001010E
    (RPC_E_WRONG_THREAD))."   Source="Microsoft.Office.Interop.Excel"<br>
    StackTrace:
           at Microsoft.Office.Interop.Excel._Worksheet.get_Shapes()
           at KGD6ExcelReader.ExcelManager.CopyToClipBoard(Worksheet worksheet, Int32 iRowindex, String strApplicationPath) in
    D:\ParallelMinds\Shared\KGD6ExcelReader\KGD6ExcelReader\ExcelManager.cs:line
    522
           at KGD6ExcelReader.ExcelManager.&lt;>c__DisplayClass3.b__0()
    in
    D:\ParallelMinds\Shared\KGD6ExcelReader\KGD6ExcelReader\ExcelManager.cs:line
    376
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.runTryCode(Object userData)
           at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
    code, CleanupCode backoutCode, Object userData)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext
    executionContext, ContextCallback callback, Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()   InnerException:</p>
  </blockquote>