C# .NET - object reference not set to an instance of an object

Asked By Brandon Schave
09-Feb-12 06:12 PM
I have a fairly large object that also has a fairly large object within it. among other small objects like a user object, etc. I carry this object in a session. The page for this object is used in order to buy product in options per contract.

functionality on the page...

the functionality is the user comes in to a contract by default (alphabetically set up) and then chooses what products he wants to buy. Then the user buys the product for that day. The user can then either go to another day in the future by pressing the "next day" button to by product for that days as well. The user can do this for as many days out as they want. The user may also be able to go to the next contract by pressing on the "next contract" button. so the user goes through each contract, buys product for as many days out that they wants and then go to the next contract until they have made all of there purchases.

what my code does....

when i load the page for the first time, I instantiate the object, use the object and save data in it and then I put it in a session variable to keep the data that I need to know which contract I need to go to next. When the page reloads...not postback, I check to see if the session variable is null. If the session variable is not null, then i make the object equal to the session variable and use the object and data and then I save the object again in the session variable.

the problem...

The problem is that when I go through 7-20 days in the future, I get the error "object reference not set to an instance of an object" within the product object that is stored in the session. The weird thing is that this error is given on diferent days depending on the contract, but it always eventually errors out. I have noticed that if the contract has less data in it, I can go through more days before I get the error. If I go through a contract with more data, I can go through less days before I get the error.

Does anyone know why this is happening? I have tried to recreate this issue on my local in debug mode, but I never get the errors.
  Robbe Morris replied to Brandon Schave
09-Feb-12 07:03 PM
Are you expecting the object to stay in session past the predefined timeout period?  By default it is 20 minutes but this dump of all session (and other things) will also take place any time the app pool in IIS recycles.
  Brandon Schave replied to Robbe Morris
13-Feb-12 03:09 PM
I don't think it's a time issue. I cannot even get into the functionality for two minutes before I lose the object. I even tried slowing down the speed at which I am moving from page to page and that doesn't seem to matter. So I am positive it's not a timeout issue.
  Robbe Morris replied to Brandon Schave
13-Feb-12 03:17 PM
You'd need to post your code for us to look at.  Remember my previous comments though, if the app pool recycles or a timeout happens, session is lost.  I'm also assuming you are only running this on one web server.
  Brandon Schave replied to Robbe Morris
13-Feb-12 04:18 PM
yes one web server. If I instantiate another object (a public one) within an object, will the instantiated object within that object be kept in memory as long as the main object is kept in a session? Maybe that is my problem.
  Robbe Morris replied to Brandon Schave
13-Feb-12 05:17 PM
Not exactly sure what are trying to do.  Remember, the object gets serialized in and out of session and a reference is not maintained "inside" session.  Think of session as a bucket, when you pull the apple out and bite into it, the apple that was in session will not show teeth marks until you put the biten apple back into session.
Create New Account
help
part of the event: 261810501. Data: 0000: 42 75 63 6b 65 74 3a 20 Bucket: 0008: 32 36 31 38 31 30 35 30 26181050 0010: 31 0d 0a 1. . Windows Server SBS Discussions Exchange Server 2003 (1) Virtual Server (1) Outlook (1) IIS (1) MSExchangeTransport (1) Report (1) SMTP (1) RobertBefore (1) Did you remove SP2 for W2k3 part of the event: 261810501. Data: 0000: 42 75 63 6b 65 74 3a 20 Bucket: 0008: 32 36 31 38 31 30 35 30 26181050 0010: 31 0d 0a 1 Logging on the MSExchangeTransport service: 1). Start Exchange System Manager. 2). Navigate to the server object. 3). Right-click <Server object> , and then click Properties. 4). Click the Diagnostic Logging tab. 5). Under Categories, click MSExchangeTransport reply. I checked Message Tracking log, the e-mails are successfully send out. Also the IIS worker process error is not cause of the problem. From MSExchangeTransport event 7002 and 4007
SP1 with Echange 6.5.7638.1 and all patches other than W2003 SP2. All IIS default website permissions and Exchange virtual Folder permissions / access settings are correct (as per MS click Run, type ncpa.cpl, and then click OK. 2. Right-click a network adapter object, and then click Properties. 3. Click Configure, and then click the Advanced tab. 4. In Not sure if it is relevant but I got an application error ID 1001 "fault bucket" following the reboot and an Application Error 1000 "faulting appliation RPCServ.exe module ntdll.dll
dbo.tbPrerequisiteDependency Creating table dbo.tbBundleDependency Creating table tbUpdateStatusPerComputer Caution: Changing any part of an object name could break scripts and stored procedures. Creating table tbUpdateSummaryForAllComputers Creating table tbComputerSummaryForMicrosoftUpdates Creating table context to 'SUSDB'. Creating table tbEventMessageTemplate Creating table tbEventInstance Caution: Changing any part of an object name could break scripts and stored procedures. Creating table tbEvent Creating table tbEventSource Creating table CERTIFICATE [MS_SchemaSigningCertificate7B0D0655F517A6AB2E4CD4BC564FAAF9966B5A88] ATTESTED BY 'C: \ WINDOWS \ SYSMSI \ SSEE \ MSSQL.2005 \ MSSQL \ SchemaSig \ WSUSSignDb.dll' Signing object:[dbo].[spDeployRevisionToDss] Signing object:[dbo].[tbTargetInTargetGroup] Signing object:[dbo].[fnGetTimeFromBlob] Signing object:[dbo].[spFireStateMachineEvent] Signing object:[dbo].[tbSchedule] Signing object:[dbo].[spGetAutoDeploymentRuleByID] Signing object:[dbo].[fnGetLocalUpdateID] Signing object:[dbo].[tbBundleDependency] Signing object:[dbo].[spGetNotificationEventItem] Signing
IIS Object Cache IIS Is IIS Obeject Cache is enabled in IIS 6.0 be default? How to find out if IIS Object Cache is enabled or not? Is there a key in the registry or metabase? IIS Discussions IIS 6.0 (1) IIS (1) Obeject (1) Shashi (1) Adjustments (1) Electrons (1