'ActiveX can't create object' error with COM Interop...

M

Munsifali Rashid

Hi,

I've built a webservice in C# that can add public folders to Exchange.
There's also a component built in VB6 which references the Outlook 10 (XP)
DLL, so I can change the default form being used to post to a public folder.
The component works fine when instantiated from a Windows script, but when
using it from COM Interop in an ASP.NET web application it errors when
trying to execute oNs.GetNameSpace("MAPI").

The error it throws up is 'ActiveX cant create object'. This sounds like a
permissions issue, so I changed web.config and IIS to make the ASP.NET web
application impersonate the administrator account, but without any luck.

A sample of my VB6 code:
(The project references cdo.dll and msoutl.olb)

Public Function UpdateFolder()

'Declare variables
Dim objSession As New MAPI.Session
Dim oFolderA As Outlook.mapiFolder
Dim oFolderTmp As Outlook.mapiFolder
Dim oFolderB As MAPI.Folder
Dim oOutlook As New Outlook.Application
Dim oNs As Outlook.NameSpace
Dim tmpFolder As Outlook.mapiFolder

'Get items from Outlook
Set oNs = oOutlook.GetNamespace("MAPI")

'More stuff here, but taken out to keep this example short.
'The line above is where it hangs.

End Function


The DLL is referenced in my Web Application, and is called using the
following:

Project1.Class1 Obj = new Project1.Class1();
Obj.UpdateFolder();

The VB6 component uses MAPI which I know can't be used from ASP.NET due to
issues with threading, but I don't think this is causing it, as it's all in
the VB6 component (which was built to get around the problem of it not
working in .net).

If this can't be done, then I might have to write a Windows service, which
is called by the webservice, and invokes the VB6 component method to change
the default form. Or maybe find a way of executing a Windows Script from
ASP.NET (something which I've had no joy with so far). Both these methods
are long ways of doing it, and which I'd like to avoid if possible.

Any help is appreciated. Cheers.

Mun
 
N

Natty Gur

Hi,

1) I hope you use tlbimp and you are working against the .NET assembly
that tlbimp create.

2) did you add Impersonate=true in your web.config to accomplish
impersonating of IIS settings ?

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
M

Munsifali Rashid

Hi,

Thanks for the response.

I added the reference to my project in VS.NET using the 'Add Reference'
option. Does this automatically create the .net assembly or do I have to
use tlbimp to create this manually?

Yep, I did add <identity impersonate = "true" /> in web.config so that the
..net web application uses the credentials passed to it from IIS rather than
it's own ASPNET account.

Mun
 
N

Natty Gur

No, use tlbimp and make reference to the output assembly.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
M

Munsifali Rashid

Tried it, and I get the same error. The command I used was tlbimp
project1.dll /out:project1_interop.dll /namespace:project1. Then I added
reference project1_interop.dll (tlbimp created file) rather than
project1.dll (VB6 compiled file).

It still throws up the 'ActiveX cant create object' error when I call Set
oNs = oOutlook.GetNameSpace("MAPI") command (Where oOutlook is New
Outlook.Application).

Looks like I'm gonna have to find a different way of making this work :-/

Thanks for your help.

Mun
 
N

Natty Gur

Just a thought, if you try to call the COM object directly (via vbs
file) is it working ?

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 
M

Munsifali Rashid

Yep, if I create a windows script (VBS) file it works fine:

Dim Obj: Set Obj = CreateObject("Project1.Class1")
Call Obj.UpdateFolder()
Set Obj = Nothing

I'm looking into it now, and it's gotta be something with permissions. I'm
thinking about trying it in a COM+ application... I've created another
simple component in VB6 which calls the GetNameSpace method. If I call this
from an ASP.NET application it throws up the error, but if I call it from a
C# Windows Application, it works fine.

I thought it might be caused if the ASPNET account didn't have permissions
to access the Outlook DLL (msoutl.olb), but I've given everyone permisisons
to that file and it still doesn't work. Maybe the GetNameSpace method is
reference from another DLL which doesn't have permissions.

But then again, I'm forcing the Web Application to impersonate the
Administrator's account anyway, so permissions can't be an issue. This
one's got me a bit puzzled...

Mun
 
M

Munsifali Rashid

I think I've worked out why it's happening, but not a solution.

The code relies on Outlook to do the MAPI related stuff, and also on Outlook
having an account registered which has acccess to public folders (i.e. using
the mail icon in control panel). I.e. If no mail profile exists in Outlook,
the code breaks, as it can't access the public folders to do what its gotta
do.

When I run my component using an application or a Windows Script, it's using
the interactive user, which is why it works - Outlook has a profile set up.
With the Web Application, despite using impersonation, only permissions are
being impersonated, but when the component loads Outlook and tries to get
the MAPI namespace, it can't because it doesn't exist - as no mail profile
exists in Outlook.

Now I've just gotta test this by removing the profile from Outlook for the
interactive user, and then running the code to see if it throws up the same
error in the same place.

Mun
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top