title: Object Reference Not Set To An Instance Of An Object. Error Comes Whenever I Used To Send value Through Session
body: <pre><code>public class Handler : IHttpHandler 
  {
  
      public void ProcessRequest (HttpContext context) {
          using (Bitmap b = new Bitmap(250, 50))
          {
              Font f = new Font("Arial", 10F);
              Graphics g = Graphics.FromImage(b);
              SolidBrush whiteBrush = new SolidBrush(Color.Blue);
              SolidBrush blackBrush = new SolidBrush(Color.White);
              RectangleF canvas = new RectangleF(0, 0, 250, 50);
              g.FillRectangle(whiteBrush, canvas);
              string i = GetRandomString();
              context.Session["Captcha"] = i; // Error Msg Object reference not set to an instance of an object.
              g.DrawString(context.Session["Captcha"].ToString(), f, blackBrush, canvas);
              context.Response.ContentType = "image/gif";
              b.Save(context.Response.OutputStream, ImageFormat.Gif);
          } 
      }
  
      public bool IsReusable {
          get {
              return false;
          }
      }
      private string GetRandomString()
      {
          string[] arrStr = "A,B,C,D,1,2,3,4,5,6,7,8,9,0".Split(",".ToCharArray());
          string strDraw = string.Empty;
          Random r = new Random();
          for (int i = 0; i &lt; 5; i++)
          {
              strDraw += arrStr[r.Next(0, arrStr.Length - 1)];
          }
          return strDraw;
      } 
  
  }
  </code></pre>
  
  <p><code>Object reference not set</code> error comes when the break pointer comes on this line:    </p>
  
  <pre><code>context.Session["Captcha"] = i;
  </code></pre>