Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Object reference not set to an instance of an object.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
j.t.w - 05 Feb 2008 10:08 GMT
Hi.

I'm following along with the learnvisualstudio.net videos. Everything
works in VWD but, when I upload my files to the web server, the pages
for the 3rd and 4th videos don't work.

For both pages, I'm getting an "Object reference not set to an
instance of an object." error message.

Video 3
Is erroring on "Page.Response.Write("User Count: " &
Application("userCount").ToString())".

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an
object.]
  v_lesson03.Page_Load(Object sender, EventArgs e) in C:\DATA\webs\jtw
\MySite.com\VideoLesson3\v-lesson03.aspx.vb:17
  System.Web.UI.Control.OnLoad(EventArgs e) +99
  System.Web.UI.Control.LoadRecursive() +47
  System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1436

Video 4
Is erroring on "resultLabel1.Text = Session("SomeValue").ToString()".

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
  _04_v_lesson04.Button1_Click(Object sender, EventArgs e) in C:\DATA
\webs\jtw\MySite.com\VideoLesson4\v-lesson04.aspx.vb:8
  System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
  System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +107

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +11
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
  System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+1746

Does anyone have any suggestions I could try to solve these problems.

TIA,
j.t.w
Coskun SUNALI [MVP] - 05 Feb 2008 11:13 GMT
Hi,

Application("userCount") might be "null" and calling ToString method on a
null object would throw the null reference exception.

Would you consider checking if it is null or using explicit conversion?

Either:

if (Application("userCount") != null)
   Application("userCount")............

Or:

Application("userCount") as string;

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Hi.
>
[quoted text clipped - 47 lines]
> TIA,
> j.t.w
j.t.w - 05 Feb 2008 23:38 GMT
Coskun (and other gurus),

Thank you for your response. You were right; the
Application("userCount") is null.

So, my next problem seems to be that since the
Application("userCount") is null, the aspx page is not seeing the
Global.asax page where the userCount is being set.

Is there a way to connect the Global.asax to the aspx page? Or... Is
there a way for the web site to recognize the Global.asax page
automatically?

FYI. These are the sub procedures that are in my Global.asax page.

   Sub Application_Start(ByVal sender As Object, ByVal e As
EventArgs)
       Application("userCount") = 0
   End Sub

   Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
       Application("userCount") += 1
       Session.Add("SomeValue", Session.SessionID)
   End Sub

   Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
       Application("userCount") -= 1
   End Sub

Again, Thank you for any help you can provide.

j.t.w
Coskun SUNALI [MVP] - 06 Feb 2008 10:21 GMT
Hi,

There is not a special way of registering your Global.asax file. It should
be used by your web application as long as it is in the root folder.

If you think that it does not work for some reason - that doesn't come to my
mind now - you may want to create a basic HttpModule implementation of yours
and do anything you can do in a Global.asax file inside your HttpModule.

Please read the article at http://support.microsoft.com/kb/307996

Signature

All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

> Coskun (and other gurus),
>
[quoted text clipped - 28 lines]
>
> j.t.w

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.