COMException

J

Jennifer

I am writing an ASP.NET/C# application and having trouble with outlook. I
keep receiving this error.

Exception Details: System.Runtime.InteropServices.COMException: Retrieving
the COM class factory for component with CLSID
{0006F03A-0000-0000-C000-000000000046} failed due to the following error:
80040154.

Source Error:

Line 1196: {
Line 1197: // Create an Outlook application.
Line 1198: Outlook.Application oApp = new Outlook.ApplicationClass();
Line 1199:
Line 1200: // Get the Mapi NameSpace and the Logon.


I do not know how to fix this. Please help!

Jennifer
 
K

Ken Slovak - [MVP - Outlook]

Where is this code running? Normally ASP.NET code runs on the server and
unless you have Outlook installed and configured on the server the code
would error.

If the code is running on a client where Outlook is installed then you have
to verify if script code can run on that computer, if the code has to be
signed and designated as safe for scripting and safe for initialization.
 
J

Jennifer

Currently I have it running on localhost (my machine) and Outlook is
installed. The code ran a couple of times an then this error appeared.
When I run this code in debug mode I do not recieve this error. I have
checked the regedit CLSID and the <default> value is not set. I am not sure
what else to do?
 
J

Jennifer

I mean the regedit CLSID <default> value is set to OUTLOOK.EXE. When I
typed the path in the Run dialog box Outlook came up, so I assume that the
path is correct.
 
K

Ken Slovak - [MVP - Outlook]

You will probably need to set security on the application, sign it and
install it for it to run in non-debug mode, but that's a question for an
ASP.NET group that deals with deployment. I don't do much ASP programming so
I don't have an answer for that.

Do you have scripting enabled in your browser and other conditions set so
ASP code can run?

When you do deploy you will need to account for all the things I mentioned
and run the code client side unless you only want to access Outlook
installed on the server.
 
D

Dmitry Streblechenko

I think she means that both the IIS and server and the client are on the
same machine.
Since this is C#, and IE does not run any .Net code the way it runs VB and
Java Scrips, I suspect that the code is actually executed in the IIS server
context (which is a service), and no Office app (inclusing Outlook) should
be used in any Windows service.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
K

Ken Slovak - [MVP - Outlook]

Right, the localhost server is local but that may not be the deployment
target. However, in any case the code should not be run server side, as
Dmitry also indicated.
 
J

Jennifer

I will not be running this on an Exchange server. I have built a web
application that accesses a Shared Outlook Calendar that sits on an Exchange
Server. I have downloaded the PIA's for Office 2003 and added the COM
reference to the project. I do not understand this error. It seems to
error on this line: Outlook.Application oApp = new
Outlook.ApplicationClass();

The rest of the code is as follows:

// Get the Mapi NameSpace and the Logon.

Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");



// Log on using dialog to choose a profile.

oNS.Logon(Missing.Value, Missing.Value, true, true);



Outlook.MAPIFolder olFolder = oNS.Folders["Public Folders"].Folders["All
Public Folders"].Folders["SRCPA Office Calender"];



// Define the string for the search criteria.

Outlook.Items oItems = olFolder.Items;



// Use the Find method to get single match.

string sFilter;

sFilter = "[Start] <= '04/11/2007 11:59 PM' and [End] > '04/11/2007 12:00
AM' and [Subject] = 'Troy Out'";

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oItems.Find(sFilter);



Please help me understand what I have done wrong.

Thank you!
 
D

Dmitry Streblechenko

The question is not whether your code is running on an Exchange Server, but
whether you are using the Outlook Object Model from a Windows *Service* (not
Server).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Jennifer said:
I will not be running this on an Exchange server. I have built a web
application that accesses a Shared Outlook Calendar that sits on an
Exchange Server. I have downloaded the PIA's for Office 2003 and added the
COM reference to the project. I do not understand this error. It seems to
error on this line: Outlook.Application oApp = new
Outlook.ApplicationClass();

The rest of the code is as follows:

// Get the Mapi NameSpace and the Logon.

Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");



// Log on using dialog to choose a profile.

oNS.Logon(Missing.Value, Missing.Value, true, true);



Outlook.MAPIFolder olFolder = oNS.Folders["Public Folders"].Folders["All
Public Folders"].Folders["SRCPA Office Calender"];



// Define the string for the search criteria.

Outlook.Items oItems = olFolder.Items;



// Use the Find method to get single match.

string sFilter;

sFilter = "[Start] <= '04/11/2007 11:59 PM' and [End] > '04/11/2007 12:00
AM' and [Subject] = 'Troy Out'";

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oItems.Find(sFilter);



Please help me understand what I have done wrong.

Thank you!




Ken Slovak - said:
Right, the localhost server is local but that may not be the deployment
target. However, in any case the code should not be run server side, as
Dmitry also indicated.
 
J

Jennifer

I am sorry, I know this is probably a dumb question, but this is all new to
me. I am using Outlook Object Model but I do not know if it is from a
Windows Service because it comes from the COM references in Visual
Studio.NET.

The project we have created takes user input to fill out an ASP.NET web
form. When the button click event occurs, the appointment item is written
to a Shared Outlook Calendar. I currenly am using Outlook 2003 and Visual
Studio 2005.

Dmitry Streblechenko said:
The question is not whether your code is running on an Exchange Server,
but whether you are using the Outlook Object Model from a Windows
*Service* (not Server).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Jennifer said:
I will not be running this on an Exchange server. I have built a web
application that accesses a Shared Outlook Calendar that sits on an
Exchange Server. I have downloaded the PIA's for Office 2003 and added
the COM reference to the project. I do not understand this error. It
seems to error on this line: Outlook.Application oApp = new
Outlook.ApplicationClass();

The rest of the code is as follows:

// Get the Mapi NameSpace and the Logon.

Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");



// Log on using dialog to choose a profile.

oNS.Logon(Missing.Value, Missing.Value, true, true);



Outlook.MAPIFolder olFolder = oNS.Folders["Public Folders"].Folders["All
Public Folders"].Folders["SRCPA Office Calender"];



// Define the string for the search criteria.

Outlook.Items oItems = olFolder.Items;



// Use the Find method to get single match.

string sFilter;

sFilter = "[Start] <= '04/11/2007 11:59 PM' and [End] > '04/11/2007 12:00
AM' and [Subject] = 'Troy Out'";

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oItems.Find(sFilter);



Please help me understand what I have done wrong.

Thank you!




Ken Slovak - said:
Right, the localhost server is local but that may not be the deployment
target. However, in any case the code should not be run server side, as
Dmitry also indicated.




I think she means that both the IIS and server and the client are on the
same machine.
Since this is C#, and IE does not run any .Net code the way it runs VB
and Java Scrips, I suspect that the code is actually executed in the
IIS server context (which is a service), and no Office app (inclusing
Outlook) should be used in any Windows service.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
D

Dmitry Streblechenko

ASP runs under IIS, which is a Windows service.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Jennifer said:
I am sorry, I know this is probably a dumb question, but this is all new to
me. I am using Outlook Object Model but I do not know if it is from a
Windows Service because it comes from the COM references in Visual
Studio.NET.

The project we have created takes user input to fill out an ASP.NET web
form. When the button click event occurs, the appointment item is written
to a Shared Outlook Calendar. I currenly am using Outlook 2003 and Visual
Studio 2005.

Dmitry Streblechenko said:
The question is not whether your code is running on an Exchange Server,
but whether you are using the Outlook Object Model from a Windows
*Service* (not Server).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Jennifer said:
I will not be running this on an Exchange server. I have built a web
application that accesses a Shared Outlook Calendar that sits on an
Exchange Server. I have downloaded the PIA's for Office 2003 and added
the COM reference to the project. I do not understand this error. It
seems to error on this line: Outlook.Application oApp = new
Outlook.ApplicationClass();

The rest of the code is as follows:

// Get the Mapi NameSpace and the Logon.

Outlook.NameSpace oNS = (Outlook.NameSpace)oApp.GetNamespace("MAPI");



// Log on using dialog to choose a profile.

oNS.Logon(Missing.Value, Missing.Value, true, true);



Outlook.MAPIFolder olFolder = oNS.Folders["Public Folders"].Folders["All
Public Folders"].Folders["SRCPA Office Calender"];



// Define the string for the search criteria.

Outlook.Items oItems = olFolder.Items;



// Use the Find method to get single match.

string sFilter;

sFilter = "[Start] <= '04/11/2007 11:59 PM' and [End] > '04/11/2007
12:00 AM' and [Subject] = 'Troy Out'";

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oItems.Find(sFilter);



Please help me understand what I have done wrong.

Thank you!




Right, the localhost server is local but that may not be the deployment
target. However, in any case the code should not be run server side, as
Dmitry also indicated.




I think she means that both the IIS and server and the client are on
the same machine.
Since this is C#, and IE does not run any .Net code the way it runs VB
and Java Scrips, I suspect that the code is actually executed in the
IIS server context (which is a service), and no Office app (inclusing
Outlook) should be used in any Windows service.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top