I am so confused as to why this is happenning in my application. I have an object I am getting from Session storage however in some cases it may not exist so I am doing some ternary checks. Even with the ternary checks I am erroring out with a Null Reference Exception on userInfo. The other weird part is that when I inspect firstName and lastName they both show "???".
@{
// Session storage for user info
var userInfo = Session["UserInfo"] as UserInfo;
var firstName = userInfo != null ? userInfo.FirstName : "???";
var lastName = userInfo != null ? userInfo.LastName : "???";
}
<div>
@firstName @lastName // Errors here with object reference not set to an instance of an object. 'userInfo' was null
</div>
Am I crazy? I swear this is how I could check against null problems.