glschill Posted November 12, 2003 Posted November 12, 2003 (edited) In my class object I am trying to access the cache object and am receiving an "Object Reference Not Set To Instance Of An Object" wherever I try to use it. See code below. This is a simple example of a more complex task that I am trying to accomplish, but I still can't get this to work. The code seems to work fine if I just put it in my code behind of my aspx page. This is driving me crazy...any suggestions? What I am doing wrong? Dim x As New MyCache Me.Label1.Text = (x.GetName) Code in my class file Imports System Imports System.Web.Caching Namespace AEAClasses Public Class MyCache Public Sub New() End Sub Public Function GetName() As String Dim mycache As New Cache '---------------------------------- 'ERROR ON NEXT LINE - Object Reference Not Set to Instance of an object '----------------------------------- If IsNothing(mycache("test")) Then 'Insert test into cache mycache("test") = "hello from cache" GetName = " it was nothing" Else 'Return Value GetName = mycache("test") End If End Function End Class End Namespace Edited November 12, 2003 by Robby Quote
Moderators Robby Posted November 12, 2003 Moderators Posted November 12, 2003 One problem is that you're creating a new instance of mycache each time you enter the method. I would also rename the variable so as not to have the same name as the class. Also, at the top of the page place Option Strict On Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.