Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object reference not set to an instance of an object

Status
Not open for further replies.

NickOwens

Programmer
Jan 16, 2009
2
US
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?
 
Please, ask in an .NET forum

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I've got three technologies trying to talk to each other and if they're not talking, which forum is most appropriate for the post?

Though this post includes some .NET code, the technology causing my breakdown right now is WSH using VBScript. Since the simple component is callable in ASP and produces the desired results, I am left to assume this is not a problem w/ the component. I can only be left to assume this deals w/ some unknown permission error of WSH scripts calling COM components.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top