Link to home
Start Free TrialLog in
Avatar of thomehm
thomehmFlag for United States of America

asked on

VSTO 0x800A03EC COM Exception

I have a Windows Forms application which talks to Microsoft Excel via Visual Studio Tools for Office.  In this application, having previously set (VSTO) Application.Calculation to XlCalculation.xlCalculationManual without Except, my application then sets Application.Calculation back to XlCalculation.xlCalculationAutomatic.  At this point, the application gets a System.Runtime.InteropServices.COMException of 0x800A03EC.  Before I can solve this problem, I would at least like to first find out what this error means.  It seems to be a generic Excel COM exception.  But after much googleing, I haven’t been able to find even a simple description of what the error actually says.
Any advise on how I could proceed?
ASKER CERTIFIED SOLUTION
Avatar of Usama Foad
Usama Foad
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thomehm

ASKER

Thanks UsamaFoad, at least now I know what the error means. Now I need to figure out what is causing my error.  The reference to social.msdn.com is interesting.  But it is mostly about how to set the Excel calculation to manual mode.  This  I already know how to do.  And it almost always works.  But I do get this error under certain test conditions.  Now I need to get a better definition of what those conditions are.
Avatar of Miguel Oz
Some clarifications from you:
1) Is your excel file read only?
2) Please provide code snippet where the call  to XlCalculation.xlCalculationAutomatic is done. Is it done on the main VSTO thread?
3) Are you targeting Office 2003 or 2007? What VS version are you using?
Note: Please change one of the zones to VSTO zone. (https://www.experts-exchange.com/Microsoft/Development/VSTO/)
Avatar of thomehm

ASKER

The excel file is not read only.  The target is Office 2007, using VS 2008.  I'm not sure what thread this is in.  The call to set the XlCalculation.xlCalculationAutomatic is in the context of a menu item click event.  Is there are requirement that the call to Excel VSTO happen in the same thread as it was started in?  Or more general question, could click events for the Windows Forms application occur in some thread that is unacceptable in the context of the VSTO Excel call?  Or even more general question, should I investigate this in terms or threading issues?  Is that a likely problem?  I do know that this code almost always runs without incident.  It is only in a certain environment and then only once in a while.  I might add that when I tested this on a couple of machines there was not issue.  The problem is only occurring when the application was tested by the IT department, running the test in a Virtual Machine.
Is there are requirement that the call to Excel VSTO happen in the same thread as it was started in?
>> Yes, it is a good VSTO design practice to keep the interop code (which is COM single threaded) within the VSTO main thread only.
  Or more general question, could click events for the Windows Forms application occur in some thread that is unacceptable in the context of the VSTO Excel call?
>> It depends, if your Winform is created in the same VSTO main thread, then it should be OK. I built Add-ins before and what I tend to do is to use the winform as dialogs and then come back to the main VSTO thread to execute whatever action is required. Thus , I avoid any potential crossthreading issue.
Avatar of thomehm

ASKER

Might I ask what I need to do to make sure that all of my VSTO calls are with the main VSTO thread?  I know how to do that with the regard to Windows Forms access to a control.  In that case I use the InvokeRequired and Invoke calls.  But I do not understand how I need to do this for VSTO calls.  Any help would be appreciated.