null异常错误 [英] null exception error

查看:105
本文介绍了null异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用会话对象将值从一个页面传递到另一个页面。对象变量具有正确的值但是我得到一个错误对象引用没有设置为对象的实例



可能出错了什么?





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??


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;
            }









进入其他地方时出错block !!





Error when it enters the else block!!

推荐答案

为Session变量添加值的语法是: -



例如: - 会话[MyKey] =值;



如果密钥名称不正确且未为相应密钥设置会话值,则只会发生此类问题。



注意:唯一的原因是会话没有按照你传递的密钥值。



如果这样可以解决您的问题,请告诉我,否则您可以提供更多信息以便我帮助您。
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.


这篇关于null异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆