Cannot get past Object Reference Error

D

danielle.m.manning

I have a question about a problem I am having with attempting to port
some old ASP code to ASP.NET.

We have a dll out there which we downloaded which creates GUIDs for
session management. In ASP, the function looks like this:

Function getGuid()
Dim sessionDUID
Dim MyGuid = Server.CreateObject("GuidMakr.GUID")
Dim mySession = Replace(MyGuid.GetGUID, "{", "")
MyGuid = Nothing
mySession = Replace(mySession, "}", "")
getGUID = mySession
End Function

Kind of hokey, but it was written by someone else, and for my purposes
it works just fine. However, I want to use the same functionality in
an ASP.NET framework. I have this exact same function in a class, but
I have modified it a little:
Function getGuid()
Dim sessionDUID
Dim MyGuid As New Object
MyGuid = Server.CreateObject("GuidMakr.GUID")
Dim mySession = Replace(MyGuid.GetGUID, "{", "")
MyGuid = Nothing
mySession = Replace(mySession, "}", "")
getGUID = mySession
End Function

and it blows up on this line:
MyGuid = Server.CreateObject("GuidMakr.GUID")

with this error:

Object reference not set to an instance of an object.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

Can someone give me some guidance? I'd appreciate it, thank you.

Danielle


However,
 
S

sloan

First, I'd make the new asp.net version, return an actual type, not a
generic "object" (or variant as it used to be)

Function getGuid() as System.Guid


I'm not sure if you're trying to solve this generically, or if you want a
better dot.net way.


Function getGuid() as System.Guid
return new System.Guid.NewGuid()
End Function

Function GetFriendlyGuid as string
return new
System.Guid.NewGuid().ToString().Replace("{","").Replace("}","").Replace("-"
,"")
end function


Try those

The Server.CreateObject was asp specific.

I would avoid this syntax in asp.net at all costs.

If you must use some backend COM object, add them via "Add Reference" and
declare and instantiate them explicitly.

dim abc as GuidMakr.GUID = new GuidMakr.GUID()
abc.DoSomething()

like that... (after adding the reference to the COM object)

...
 

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

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top