473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Null Reference Exception when run under machine name

I am having a very stange issue happen to my web application. I am
trying to develop a simple shopping cart. The code works perfectly
when I run the application under http://localhost/myapp. However, when
I try to run the same app under the machine name http://mymachine/myapp
I recieve a Null Reference Exception and the page crashes. I can't
figure out why this is happening. The Null Reference is referring to a
Session variable containing a dynamic DataTable which has the items the
user has chosen to purchase. The Store and the Shopping Cart are all
in 1 web form (only trying to sell t-shirts). Can anyone give me a
hint as to what may be happening. I am attaching the necessary code
snippets. Thanks in advance.

Dim objDT as DataTable = New DataTable
Dim objDR as DataRow
Private Sub Page_Load(ByVal sender as System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
makeCart()
End If

Function makeCart()
objDT = New System.Data.DataTable("Cart")
'create the columns to store the items in the shopping cart
Session("Cart") = objDT
End Function

Public Sub AddToCart(ByVal s As Object, ByVal e As EventArgs) 'this
handles the click event to add items to the cart.
objDT = Session("Cart")
For Each objDR In objDT.Rows 'this is the line which throws the
Null Reference error. After debugging I found that the Session("Cart")
= Nothing. As I mentioned above, this problem does not occur when run
under 'localhost'.
'do some stuff here
Next
End Sub

Jul 21 '05 #1
2 1893
the way i did in mastermind and ludo, chinese-checker, draughts, etc,
games using gdi in vb. i know errror problem when creating games. there
is nothing wrong with ur code. the only problem is coming from page_load
procedure..that is only way i know is coming from load event because i
used games programming .
this is how i do in games:

Dim PegHole As Image
Private Function CreatePegHoleImage() As Image
\\
\\
end Function
if i didn't add in form_load...i will get same error.

if i add in form_load( )
private sub form_load(byval........, ..........)
PegHole = Me.CreatePegHoleImage() <===== that is only way prevent error
end sub

but i haven't done yet datattable....but u can try this in below...

Private Sub Page_Load(ByVal sender as System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
objDR=me.makecart()
End If

regards


Shannon wrote:
I am having a very stange issue happen to my web application. I am
trying to develop a simple shopping cart. The code works perfectly
when I run the application under http://localhost/myapp. However, when
I try to run the same app under the machine name http://mymachine/myapp
I recieve a Null Reference Exception and the page crashes. I can't
figure out why this is happening. The Null Reference is referring to a
Session variable containing a dynamic DataTable which has the items the
user has chosen to purchase. The Store and the Shopping Cart are all
in 1 web form (only trying to sell t-shirts). Can anyone give me a
hint as to what may be happening. I am attaching the necessary code
snippets. Thanks in advance.

Dim objDT as DataTable = New DataTable
Dim objDR as DataRow
Private Sub Page_Load(ByVal sender as System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
makeCart()
End If

Function makeCart()
objDT = New System.Data.DataTable("Cart")
'create the columns to store the items in the shopping cart
Session("Cart") = objDT
End Function

Public Sub AddToCart(ByVal s As Object, ByVal e As EventArgs) 'this
handles the click event to add items to the cart.
objDT = Session("Cart")
For Each objDR In objDT.Rows 'this is the line which throws the
Null Reference error. After debugging I found that the Session("Cart")
= Nothing. As I mentioned above, this problem does not occur when run
under 'localhost'.
'do some stuff here
Next
End Sub


Jul 21 '05 #2

Thanks for the tip, but unfortunately the problem still exists. I will
try to work out some variations of how the variable is loaded based upon
your comments. If you have further insight, please let me know.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
7
by: odonel | last post by:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: here is my code: HttpCookie cookie = Request.Cookies;
4
by: rrober07 | last post by:
Hello, My Setup is I have a Web Server machine(Devweb01), Database SQL Machine(Devsql01), a Client Machine(local machine) I have configured the SQL machine as follows: 1) Added local Aspnet...
16
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project -...
2
by: Shannon | last post by:
I am having a very stange issue happen to my web application. I am trying to develop a simple shopping cart. The code works perfectly when I run the application under http://localhost/myapp. ...
1
by: connor7777 | last post by:
Hi guys: We've been weeding out errors off of a java->c# project and have managed to redeem most of our code with the exception of one bug that we for some reason cannot pin down. The following...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
1
by: vaibhavchavan | last post by:
Hi I am doing application for signing of soap message with digital certificate . I am using WSE 2.0 I worte the the simple webservice & deployed it on in our server machine . To make it...
2
by: Febria | last post by:
Dear, all... I have some problem with my application. I used UltraWebGrid component in my web application. Unfortunately, when I tried to run the web, the error page displayed: The located...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.