Classic ASP, Cookies, and VB.NET COM+ objects

1.1k views Asked by At

This is tangled.

I've been handed a web site written in classic ASP, with a lot of behind the scenes stuff done in VB6 COM+ objects called from the ASP pages via Server.ObjectCreate() instantiations. For this incarnation, the VB6 routines have been converted to VB.NET simply by running the Visual Studio 2003 converter tool on them, and then upgrading that solution file to VS 2008. So there's a thousand and one possible sources for error.

One of the VB6 Modules that is giving me trouble clears a bunch of Response cookies by lines of the following form:

ASPResponse.Cookies("SysUserCode") = ""

Where ASPResponse is defined as :

Private ASPResponse As ASPTypeLibrary.Response

And was set up on Object Activation by:

Set ASPResponse = objContext("Response")

In the VB.NET conversion of this module, those lines became

ASPResponse = ContextUtil.GetNamedProperty("Response")

and

ASPResponse.Cookies("SysUserCode")() = ""

(note the extra pair of parentheses. Not being much of a VB person, I'm not real sure what that syntax means.)

Okay, here's the question: When this code executes on MY machine, that line is giving a VB error 13, with the Error.Description being "Specified cast is not valid." Huh? What cast?

Incidentally, this module runs fine on a co-workers machine, and he cannot see any difference in the configuration of my machine and the relevant components from his.

I'm totally at a loss here. Googling it has given me a bunch of stuff on VB.NET cookies, or COM components with VB.NET, but nothing related to classic ASP cookies.

2

There are 2 answers

3
George Johnston On

Is...

Private ASPResponse As ASPTypeLibrary.Response
Set ASPResponse = objContext("Response") 

...Post VB.NET conversion? If so, you'll need to explicitly cast objContext("Response") into the ASPTypeLibrary.Response object. This especially applies if Option Strict is on. e.g.

ASPResponse = CType(objContext("Response"), ASPTypeLibary.Response)

Also, Set and Let statements aren't supported in VB.NET.

0
Dave Hanna On

This MAY have to do with the way the COM component's host is activated. I read another post ([Klaus H. Probst])1 that indicated that, in order to access the Response element, the COM component had to be activated as a Library (as opposed to Server) so that it was running in the ASP process space. So I tried changing the Activation type of the Component's hosting application to library, resetting and rebuilding a few times, and now I'm able to access the Cookies element of the Response. However, my co-worker is still running the host application as a Server, and has no problem.