这很纠结。
我收到了一个用经典 ASP 编写的网站,其中许多幕后工作是通过 Server.ObjectCreate() 实例从 ASP 页面调用的 VB6 COM+ 对象完成的。对于此版本,只需在其上运行 Visual Studio 2003 转换器工具,然后将该解决方案文件升级到 VS 2008,即可将 VB6 例程转换为 VB.NET。因此,存在一千零一个可能的错误源。
给我带来麻烦的一个 VB6 模块通过以下形式的行清除了一堆响应 cookie:
ASPResponse.Cookies("SysUserCode") = ""
其中 ASPResponse 定义为:
Private ASPResponse As ASPTypeLibrary.Response
并且在对象激活上设置为:
Set ASPResponse = objContext("Response")
在该模块的 VB.NET 转换中,这些行变成了
ASPResponse = ContextUtil.GetNamedProperty("Response")
and
ASPResponse.Cookies("SysUserCode")() = ""
(注意额外的一对括号。我不太懂 VB,我不太确定该语法的含义。)
好的,问题是:当这段代码在我的机器上执行时,该行给出了一个 VB错误 13,Error.Description 为“指定的转换无效”。啊?什么演员阵容?
顺便说一句,这个模块在同事的机器上运行良好,他看不出我的机器的配置和他的相关组件有任何差异。
我在这里完全不知所措。谷歌搜索给了我很多关于 VB.NET cookie 或带有 VB.NET 的 COM 组件的信息,但没有任何与经典 ASP cookie 相关的信息。
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)
是...
...后 VB.NET 转换吗?如果是这样,您需要将
objContext("Response")
显式转换为ASPTypeLibrary.Response
对象。如果Option Strict
启用,这一点尤其适用。例如,VB.NET 不支持Set 和Let 语句。
Is...
...Post VB.NET conversion? If so, you'll need to explicitly cast
objContext("Response")
into theASPTypeLibrary.Response
object. This especially applies ifOption Strict
is on. e.g.Also, Set and Let statements aren't supported in VB.NET.
这可能与 COM 组件主机的激活方式有关。我读了另一篇文章 ([Klaus H. Probst])1 表明,为了要访问 Response 元素,COM 组件必须作为库(而不是服务器)激活,以便它在 ASP 进程空间中运行。因此,我尝试将组件托管应用程序的激活类型更改为库,重置和重建几次,现在我可以访问响应的 Cookies 元素。但是,我的同事仍然将主机应用程序作为服务器运行,并且没有问题。
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.