views:

30

answers:

2

Hello,

I am facing a very strange issue. I get an error Object Reference Not set to instance of object on the server while the code runs fine on my dev machine. The strange part is the line number where the code is throwing error (as appears in the Stack trace)

DemoUser demoUser = new DemoUser();

if (!Request.QueryString.AllKeys.Contains("name"))
{
  playerName = usr.NinjaName;
  demoUser.Email = usr.UserEmail;
  demoUser.UserPicture = usr.UserPicture;
}
else
{
  playerName = Request.QueryString["name"];
  demoUser.Email = String.Empty;
  demoUser.UserPicture = "http://graph.facebook.com/1/picture";
}         

demoUser.EntryDateTime = DateTime.Now;
demoUser.Name = playerName;

Session["DemoUser"] = demoUser;

imgPlayer.ImageUrl = demoUser.UserPicture; // This is throwing error. 

If that line is throwing error then the demoUser object is getting lost when I assign it to Session. Is that right?

A: 

Try:

demoUser = (DemoUser)Session["DemoUser"]; 

imgPlayer.ImageUrl = demoUser.UserPicture;
IrishChieftain
+2  A: 

Are you sure that demoUser is the null reference and not imgPlayer?

LukeH
+1 : Possible Cause
saurabh
That indeed was the cause. The code on the dev and server were different, which means visual studio publishing did not publish the changes on this file. Strange as all other changes seem to be reflected.
sassyboy