We are encountering a strange issue when trying to automate Excel using the AutomationFactory in a Trust In Broswer Silverlight 5 application.
This code runs on the UI thread in Application_Startup:
dynamic excel = AutomationFactory.CreateObject("Excel.Application");
excel.Visible = false;
dynamic workbooks = excel.workbooks;
workbooks.Open(@"C:\temp\test.xlsm");
excel.Run("Test");
Note: The excel file is just a dummy excel file with a stub macro called Test()
that does nothing. The file exists and is in the correct location.
The first time through a RuntimeBinderException
is thrown at excel.Run("Test");
'object' does not contain a definition for 'Run'
Immediately after this, running the code again causes a RuntimeBinderException to be thrown earlier, at excel.Visible = false;
'object' does not contain a definition for 'Visible'
I checked the exact same code and setup on 2 coworkers machines and all of the statements executed correctly without exception.
I suspect something is happening behind the scenes in the AutomationFactory or with the COM objects or even with my VisualStudio setup, but I do not know enough about it to correctly debug or what to check. Perhaps something is amiss in DCOMCNFG?
Any ideas are appreciated.
Thank you,
Dan