Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am using a session object to pass values from one page to another. the object variables are having proper values but but i am getting an error " object Reference not set to instance of an object"

what might be wrong??


C#
try
            {
                objFilingCommonEntityciv = Session[Constant.Filed] as CommonEntity;
                if (objFilingCommonEntityciv != null)
                {
                    string a = string.Empty;
                    
                    a = objFilingCommonEntityciv.Type;
                    if (a =="good")
                    {
                        lblnoteName.Text = "MORNING";
                        lblbookValue.Text = "MOrning";
                    }

                    else
                    {
                        lblnoteName.Text = "night";
                        lblbookValue.Text = "night";
                    }
                    
            }
            catch (Exception ex)
            {
                Logger.Error(Error encountered at loaddata, ex);
                throw;
            }




Error when it enters the else block!!
Posted
Updated 4-May-14 22:53pm
v4
Comments
Kornfeld Eliyahu Peter 5-May-14 2:28am    
You have a variable that was not initialized so it still null, but no one can tell which variable without your code!
King Fisher 5-May-14 2:30am    
post your code
ravikhoda 5-May-14 2:59am    
add some code.
Sibasisjena 5-May-14 3:00am    
Post your codes
King Fisher 5-May-14 3:18am    
Example :
http://www.aspdotnet-suresh.com/2012/11/aspnet-session-state-example-in-c-vbnet.html

1 solution

Syntax for adding values to Session variable is :-

Ex :- Session["MyKey"] = value;

If the key name is not proper and the session value is not set for the respective key then only this kind of issue might happen.

NOTE : The only reason is the session is not having the value as per the key you passed.

Please let me know if this solves your issue or else you can give some more information for me to help you.
 
Share this answer
 
Comments
Member 10604424 5-May-14 3:15am    
sorry it dint solve my question.....i have used the same code for previous level also....
2nd level object name was objFilingCommonEntitycivang
SRS(The Coder) 5-May-14 7:29am    
It seems the value for the Session variable "Session[Constant.Filed]" is not existing at all.
reasons may be :
i) Constant.Filed does not contains the same key name for which value is being added.<br><br>
ii) Nothing set to session for the particular key Constant.Filed before trying to fetching it.<br><br>
iii) Session value is being cleared before fetching the value for it.
Check session values by debugging in all above scenario.
Also might be redirecting to the other page some where clearing the session is occurring.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900