Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem retrieving object from Session

Problem retrieving object from Session

Scheduled Pinned Locked Moved ASP.NET
helpdotnetdebuggingquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ramin Tarhande
    wrote on last edited by
    #1

    I store my data in an object an put it into Session sometimes when I want to get back the object from session I encounter an error message saying the object is null note: -the object is large (including some DataSets) -when I run in Debug mode it always works ok! could anybody help me solve the problem? :confused: thx il nome mio nessun sapra

    C 1 Reply Last reply
    0
    • R Ramin Tarhande

      I store my data in an object an put it into Session sometimes when I want to get back the object from session I encounter an error message saying the object is null note: -the object is large (including some DataSets) -when I run in Debug mode it always works ok! could anybody help me solve the problem? :confused: thx il nome mio nessun sapra

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Without seeing more of your code it's difficult to say. However, the following is a good set of guidlines to accessing Session variables in a safe way.

      public DataSet MyDataSet
      {
      get
      {
      return Session["MyDataSet"] as DataSet;
      }
      set
      {
      Session["MyDataSet"] = value;
      }
      }

      That was you reduce the chance of getting errors where you accidentally mistype the key string that goes in the indexer property because they will only exist twice. Secondly, the property is strongly typed. You only get a DataSet out, and you can only put a dataset in. There is no chance you accidentally put the wrong object into the Session. You will only get null out if there is nothing in the session. If you do this manually each time there is the possibility of an error putting the wrong object in the session and the Session["VariableName"] as DataSet returning null. You also mentioned that it works in Debug Mode. Are you doing anything differenly in debug builds? Do you have and #if DEBUG ... #endif blocks anywhere? --Colin Mackay--

      "In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown) Enumerators in .NET: See how to customise foreach loops with C#

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups