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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using custom COM object in class file - Object reference not set...

Status
Not open for further replies.

UViewIT

IS-IT--Management
Feb 5, 2007
21
0
0
CA
I am working on a site that has both classic ASP and .NET and have found the MSDN "SessionPage" utility to help bridge classic -> .NET session data. I have it up and running fine on my site using the demo code but am having trouble getting it to work with my own pages.

In the demo the test page code is as follows:



<%@ Page Language="C#" Debug="true" Inherits="MSDN.SessionPage" %>
"server">
private void Page_Load(object sender, System.EventArgs e)
{
Session["fName"] = "Billy";

if (Session["Count"] == null) Session["Count"] = "0";
Session["Count"] = Convert.ToString(Convert.ToInt32(Session["Count"]) + 1);
Response.Write(Session["Count"]);
Response.Write("&lt;BR>");
Response.Write(Session["fName"] + " " + Session["lName"]);
}

"-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR"&gt;
<meta content="C#" name="CODE_LANGUAGE"&gt;
<meta content="JavaScript" name="vs_defaultClientScript"&gt;
<meta content=" name="vs_targetSchema">

"Form1" method="post" runat="server">


For my site I want to have access to the Session object in a VB class file, as it holds some general site wide functions that need access to the MSDN Session object. Since this is a class file I don't have a page declaration header, so I figured I could inherit the MSDN.SessionPage class like this:



Imports System.Web
Imports System.Data.Sql
Imports System.Data.SqlClient

Public Class TestModules
Inherits MSDN.SessionPage

s_SessionText = Session("TestSessionText")



The error I get is "Object reference not set to an instance of an object." on the s_SessionText = Session("TestSessionText") line... I know this has to be something very dumb that I am missing but I'm pretty new at all of this and just can't figure it out. Anyone have any tips or ideas?

Thanks,
Mike
 
The first thing wrong I see is that you are mixing HTML with the code. This is classic ASP coding. With .NET you should use the code-behind page for your code. Also, I don't see where you declare your s_SessionText variable.
 
The first code chunk is provided by the MSDN team when they developed this component. I know they are mixing HTML & code but it does work as a .NET page just fine.

In the second chunk I forgot to include the declaration for s_SessionText but that doesn't make a difference with it in place... The error still occurs and is related to the "Session" object not being set to an instance.
 
Sorry but you are missing the point of my original post... I am using this COM object to bridge sessions between classic ASP & .NET, the standard .NET session structure does not do this so your suggestion is out of context.

Either way I have completed a work-around for this by passing the session values by value from the MSDN.Session* objects to the functions in my class file. Not the best solution as it requires 3-4 lines of code in each file using public functions in the class, but it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top