Solved

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

Posted on 2004-03-27
4
808 Views
Last Modified: 2007-12-19
Hi all

this is driving me slightly mad. I'm integrating two different apps, with their own authentication methods (seemed like a good idea at the time!).  It builds fine.

Making this call (userInt is set to a valid integer in both cases) in global.asax:

InstantASP.InstantForum.Logic.UserExists(userInt);

in Session_Start is working ok, but in Application_AuthenticateRequest it gives me the following error:

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

Stack Trace:
NullReferenceException: Object reference not set to an instance of an object.]
   InstantASP.InstantForum.Logic.ReturnSessionID() +15
   InstantASP.InstantForum.Logic.UserExists(Int32 UserID) +202
   CEL.Global.Application_AuthenticateRequest(Object sender, EventArgs e) in c:\inetpub\wwwroot\cel\global.asax.cs:129
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


Any pointers as to how to track down?  The object I'm calling is a compiled dll, so getting in to what it's doing is going to be tricky.  I'm wondering if there's a different context for these two parts of global.asax, but to be honest am a bit lost.

Thanks in advance
Ben
0
Comment
Question by:bjohns33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
codewiz51 earned 500 total points
ID: 10695301
If you notice, the failure occurs when the class attempts to return the sessionID:
InstantASP.InstantForum.Logic.ReturnSessionID() +15

That's because you don't have a session established at the time Application_AuthenticateRequest excutes, but it does exist by the time Session_Start executes.

This is based on wild conjecture at this point, but I am betting the original authors intended for UserExists to be excuted after a session is established.

Good luck on this.
0
 
LVL 1

Author Comment

by:bjohns33
ID: 10695464
Thanks for the response - despite your 'wild conjecture', I'm sure you're right!

So, is a solution to move all of my authentication code in to Application_OnPostRequestHandlerExecute instead, as this does have access to the session?

What will this break?

Cheers
Ben
0
 
LVL 1

Author Comment

by:bjohns33
ID: 10695806
Hi CodeWiz

Have moved it all to the Application_OnPostRequestHandlerExecute, and miracle of miracles, it works.

Thanks for pointing me in the right direction.

Cheers
Ben
0
 
LVL 2

Expert Comment

by:codewiz51
ID: 10696407
Sorry, I was cutting the grass and didn't see your responses.  Amazing, I have a life occasionally!  I'm glad moving the code worked, because I didn't have a clue as to whether anything would break if you moved it to Application_OnPostRequestHandlerExecute.  ;-)

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 41
"Emulate" TAB key when press Enter Key 3 70
bound data table problem 2 40
create dataset from text files to go on winforms gridview 3 25
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question