---
title: "Help with NullReference exception in C#"  
description: "Help with NullReference exception in C#"  
author: "Anonymous User"  
published: 2014-08-23  
updated: 2014-08-23  
canonical: https://www.mindstick.com/forum/2099/help-with-nullreference-exception-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Help with NullReference exception in C#

The following is a [web method](https://www.mindstick.com/interview/746/how-do-you-invoke-a-web-method-of-web-service-in-ajax) that is called from [ajax](https://www.mindstick.com/articles/1541/check-availability-of-user-name-or-email-using-asp-dot-net-ajax-and-jquery), I have verified with firebug that the [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) is indeed passing [two string](https://www.mindstick.com/forum/12883/how-to-extract-sub-string-between-two-string-pattern-using-javascript-jquery) [values](https://www.mindstick.com/forum/327/sum-textbox-values) to my method:

```
public string DealerLogin_Click(string name, string pass){    string g="adf";    if (name == "w" && pass == "w")    {        HttpContext.Current.Session["public"] = "pub";        g= "window.location = '/secure/Default.aspx'";    }    return g;}
```

If I [delete](https://www.mindstick.com/forum/33620/how-to-delete-record-from-list-in-mvc-using-ajax) the if [block](https://www.mindstick.com/forum/157599/explain-the-process-control-block-pcb-in-the-operating-system) then I don't get an [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) back from the server.

## Replies

### Reply by Sumit Kesarwani

Hi Goti, \

Without seeing the stack trace, I would guess that HttpContext.Current or HttpContext.Current.Session is null.


---

Original Source: https://www.mindstick.com/forum/2099/help-with-nullreference-exception-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
