It's a simple error message that we've all seen before but it's got a complex way of showing it's head that is completely reproducable but at the same time inexplicable!
Background:
For a legacy application I need a component that can access the ASP Application state across both ASP and WSH. I wrote a quick VB.NET component (source below) with an interface exposed to COM which accomplishes this using the objectContext model you see in so many examples. Sound simple?
Source:
Imports System.Runtime.InteropServices
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _Cache
<DispId(1)> Property Val(ByVal VarName) As String
End Interface
<ClassInterface(ClassInterfaceType.None), ProgId("Clixis.Application")> _
Public Class Cache : Implements _Cache
Public Property Val(ByVal VarName) As String Implements _Cache.Val
Get
Dim objAppServer As COMSVCSLib.AppServer
Dim objContext As COMSVCSLib.ObjectContext
Dim objApplication As ASPTypeLibrary.Application
objAppServer = New COMSVCSLib.AppServer
objContext = objAppServer.GetObjectContext()
objApplication = objContext("Application")
Val = objApplication(VarName)
objAppServer = Nothing
objContext = Nothing
objApplication = Nothing
End Get
Set(ByVal VarValue As String)
Dim objAppServer As COMSVCSLib.AppServer
Dim objContext As COMSVCSLib.ObjectContext
Dim objApplication As ASPTypeLibrary.Application
objAppServer = New COMSVCSLib.AppServer
objContext = objAppServer.GetObjectContext()
objApplication = objContext("Application")
objApplication.Lock()
objApplication(VarName) = VarValue
objApplication.UnLock()
objAppServer = Nothing
objContext = Nothing
objApplication = Nothing
End Set
End Property
End Class
(The actual component has several other properties and features but this simplified version with a single property produces the same effect.)
Problem:
In short: it works from ASP but not from WSH! No kidding - this error message only appears when called from WSH!
ASP Code:
<%
set cache = server.createobject("clixis.application")
response.write cache.val("test")
set cache = nothing %>
WSH Code:
set cache = createobject("clixis.application")
wscript.echo cache.val("test")
set cache = nothing
Other Information:
- My project has come to a stand still since I wrote mountains of code assuming I would get this to work and I hate to have to start from scratch if I can't get this working.
- I'll give my first born son to anyone who comes up w/ the answer. I don't have children yet so I can make this promise now and avoid the usual attachment that goes along w/ having children
- If you have questions for me or comments, you can reach me directly at (904) 429-7039 or nicowens (at) gmail.
Troubleshooting Steps:
- I have confirmed that both scripts are instantiating the same component by re-registering it w/ a different ProgId and changing the code to reflect the new name.
- While there are more complicated properties and methods in my actual class file, I reduced this one to the simple ReadWrite property you see in the example code which still produces the error.
Questions:
- Do I need to update to a newer version of Wscript if one exists? Is it possible that the elimination of the "Set" keyword in VB.NET is causing the problem for Wscript?
Background:
For a legacy application I need a component that can access the ASP Application state across both ASP and WSH. I wrote a quick VB.NET component (source below) with an interface exposed to COM which accomplishes this using the objectContext model you see in so many examples. Sound simple?
Source:
Imports System.Runtime.InteropServices
<InterfaceType(ComInterfaceType.InterfaceIsIDispatch)> _
Public Interface _Cache
<DispId(1)> Property Val(ByVal VarName) As String
End Interface
<ClassInterface(ClassInterfaceType.None), ProgId("Clixis.Application")> _
Public Class Cache : Implements _Cache
Public Property Val(ByVal VarName) As String Implements _Cache.Val
Get
Dim objAppServer As COMSVCSLib.AppServer
Dim objContext As COMSVCSLib.ObjectContext
Dim objApplication As ASPTypeLibrary.Application
objAppServer = New COMSVCSLib.AppServer
objContext = objAppServer.GetObjectContext()
objApplication = objContext("Application")
Val = objApplication(VarName)
objAppServer = Nothing
objContext = Nothing
objApplication = Nothing
End Get
Set(ByVal VarValue As String)
Dim objAppServer As COMSVCSLib.AppServer
Dim objContext As COMSVCSLib.ObjectContext
Dim objApplication As ASPTypeLibrary.Application
objAppServer = New COMSVCSLib.AppServer
objContext = objAppServer.GetObjectContext()
objApplication = objContext("Application")
objApplication.Lock()
objApplication(VarName) = VarValue
objApplication.UnLock()
objAppServer = Nothing
objContext = Nothing
objApplication = Nothing
End Set
End Property
End Class
(The actual component has several other properties and features but this simplified version with a single property produces the same effect.)
Problem:
In short: it works from ASP but not from WSH! No kidding - this error message only appears when called from WSH!
ASP Code:
<%
set cache = server.createobject("clixis.application")
response.write cache.val("test")
set cache = nothing %>
WSH Code:
set cache = createobject("clixis.application")
wscript.echo cache.val("test")
set cache = nothing
Other Information:
- My project has come to a stand still since I wrote mountains of code assuming I would get this to work and I hate to have to start from scratch if I can't get this working.
- I'll give my first born son to anyone who comes up w/ the answer. I don't have children yet so I can make this promise now and avoid the usual attachment that goes along w/ having children
- If you have questions for me or comments, you can reach me directly at (904) 429-7039 or nicowens (at) gmail.
Troubleshooting Steps:
- I have confirmed that both scripts are instantiating the same component by re-registering it w/ a different ProgId and changing the code to reflect the new name.
- While there are more complicated properties and methods in my actual class file, I reduced this one to the simple ReadWrite property you see in the example code which still produces the error.
Questions:
- Do I need to update to a newer version of Wscript if one exists? Is it possible that the elimination of the "Set" keyword in VB.NET is causing the problem for Wscript?