Excel/Outlook interop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, All!

I'm working on a C# windows service project in witch I'm using MS Excel and MS Outlook
automation objects referenced through Microsoft Excel 10.0 Object Library
and Microsoft Outlook 10.0 Object Library.

On my local computer, calling methods and accessing properties on these automation
objects works smoothly. However, when I try running the service, having deployed it on the production
server, the execution halts on the first attempt to invoke a method or access a property
on one of the automation objects. Strange thing is that no exception is thrown, the service just
halts and doesn't seem to get any further in execution.

Consider the following code snippet:

//->
Excel.Application xlApp;
Excel._Workbook xlWbk;
Excel.Worksheet xlWst;

xlApp = new Excel.Application(); // <-- The call to the Excel.Application constructor returns OK.

// However, neither of the following lines of code are ever executed.
// The execution of the service just halts, waiting for control to be
// returned from the automation object. -->

xlApp.AlertBeforeOverwriting = false;

xlWbk = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);

//<-

Just for the record, I've copied the versions of Interop.Excel.dll, Interop.Outlook.dll, Interop.VBIDE.dll
from the the project directory on my local computer, onto the production server, in the same
directory as my Windows Service executable. Any of you guys having an idea of what's causing
this problem?
 
Copying is not sufficient, you will need to register the owc10 library on
your server. Usually the install program would have done it for you,
otherwise you need regsvr32 owc10 at a command prompt where the library is
located. Reg keys need to be setup for the library to come alive.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Trond A. S. Andersen said:
Hi, All!

I'm working on a C# windows service project in witch I'm using MS Excel and MS Outlook
automation objects referenced through Microsoft Excel 10.0 Object Library
and Microsoft Outlook 10.0 Object Library.

On my local computer, calling methods and accessing properties on these automation
objects works smoothly. However, when I try running the service, having deployed it on the production
server, the execution halts on the first attempt to invoke a method or access a property
on one of the automation objects. Strange thing is that no exception is thrown, the service just
halts and doesn't seem to get any further in execution.

Consider the following code snippet:

//->
Excel.Application xlApp;
Excel._Workbook xlWbk;
Excel.Worksheet xlWst;

xlApp = new Excel.Application(); // <-- The call to the Excel.Application constructor returns OK.

// However, neither of the following lines of code are ever executed.
// The execution of the service just halts, waiting for control to be
// returned from the automation object. -->

xlApp.AlertBeforeOverwriting = false;

xlWbk = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);

//<-

Just for the record, I've copied the versions of Interop.Excel.dll,
Interop.Outlook.dll, Interop.VBIDE.dll
 
Thanks Alvin, but shouldn't the owc10 library already be registered on the server as part of the setup program installing MS Office? The OWC10.DLL was present on the server, residing in the C:\Program Files\Common Files\Microsoft Shared\Web Components\10 directory, prior to the installation of my Windows service application. Do I need to perform any explicit registration of the Interop.Excel.dll, Interop.Outlook.dll, Interop.VBIDE.dll components I've copied from my development project directory

Regards, Tron


----- Alvin Bruney wrote: ----

Copying is not sufficient, you will need to register the owc10 library o
your server. Usually the install program would have done it for you
otherwise you need regsvr32 owc10 at a command prompt where the library i
located. Reg keys need to be setup for the library to come alive

--
Regards
Alvin Brune
Got tidbits? Get it here..
http://tinyurl.com/3he3
Trond A. S. Andersen said:
Hi, All and MS Outloo
automation objects referenced through Microsoft Excel 10.0 Object Librar
and Microsoft Outlook 10.0 Object Library automatio
objects works smoothly. However, when I try running the service, havin deployed it on the productio
server, the execution halts on the first attempt to invoke a method o access a propert
on one of the automation objects. Strange thing is that no exception i thrown, the service jus
halts and doesn't seem to get any further in execution
Excel._Workbook xlWbk
Excel.Worksheet xlWst
// The execution of the service just halts, waiting for control to b
// returned from the automation object. -->>> xlApp.AlertBeforeOverwriting = false
Interop.Outlook.dll, Interop.VBIDE.dl
 
That's right. It should be registered normally. There are situations where
the registration will fail silently in which case, manual registration will
normally fix it.

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
Trond A. S. Andersen said:
Thanks Alvin, but shouldn't the owc10 library already be registered on the
server as part of the setup program installing MS Office? The OWC10.DLL was
present on the server, residing in the C:\Program Files\Common
Files\Microsoft Shared\Web Components\10 directory, prior to the
installation of my Windows service application. Do I need to perform any
explicit registration of the Interop.Excel.dll, Interop.Outlook.dll,
Interop.VBIDE.dll components I've copied from my development project
directory?
 
Thanks again, Alvin

I've 'manually' registered the OWC10 library, using regsvr32, but I regret to say that it didn't seen to do any difference
However, I wrote a simpe .NET Exel Automation Client App, which I deployed on two different production servers, using a pretty standard VS .NET Setup Project

The C# Excel Automation client code I used for my test project goes

private void button1_Click(object sender, System.EventArgs e

tr

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US")
xlApp = new Excel.Application(); // xlApp being a pivate Excel.Application class member
xlApp.Left = this.Right + 1
xlApp.Height = 256
xlApp.Width = 256
xlWbk = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet);
// xlWbk being a private Excel._Workbook class membe
xlWst = (Excel.Worksheet)xlApp.Workbooks[1].Worksheets[1]
// xlWst being a private Excel.Worksheet class membe

xlWst.get_Range("A1", Type.Missing).Value2 = "EXCEL AUTOMATION WORKS!!"
xlApp.Visible = true

this.button2.Enabled = true
this.button1.Enabled = false

catch (System.Exception se

MessageBox.Show(se.GetType().ToString() + ": " + se.Message, "Excel Automation Error"
MessageBoxButtons.OK, MessageBoxIcon.Error)



private void button2_Click(object sender, System.EventArgs e

if (xlApp != null

if(xlWbk != null && xlApp.Workbooks.Count > 0

xlWbk.Close(false, Type.Missing, Type.Missing)

xlApp.Workbooks.Close()
xlApp.Quit()


this.button2.Enabled = false
this.button1.Enabled = true


Running the above code snippet on testserver A, on which MS Excel 2002 (10.2614.3501) SP-1 is installed
the exception caught is a System.Runtime.InteropServices.COMException with an error message "Exception from HRESULT: 0x800A0EC"

On testserver B, with MS Excel 2002 (10.3506.3501) SP-1, however, execution of the code snippet results in a System.InvalidCastException, accompanied by an error message "Queryinterface for interface Excel-_Application failed"

The testapp build and the setup program used to install the automation client is the same for server A and B

Any Ideas

----- Alvin Bruney wrote: ----

That's right. It should be registered normally. There are situations wher
the registration will fail silently in which case, manual registration wil
normally fix it

--
Regards
Alvin Brune
Got tidbits? Get it here..
http://tinyurl.com/3he3
Trond A. S. Andersen said:
Thanks Alvin, but shouldn't the owc10 library already be registered on th
server as part of the setup program installing MS Office? The OWC10.DLL wa
present on the server, residing in the C:\Program Files\Commo
Files\Microsoft Shared\Web Components\10 directory, prior to th
installation of my Windows service application. Do I need to perform an
explicit registration of the Interop.Excel.dll, Interop.Outlook.dll
Interop.VBIDE.dll components I've copied from my development projec
directory
 
Back
Top