在实例化对象上是否存在NullReferenceException?
时间:2020-03-05 18:51:02 来源:igfitidea点击:
这是我继承的应用程序中的一段代码,用户死于黄屏:
Object reference not set to an instance of an object
在线上:
bool l_Success ...
现在我有95%的把握是错误的参数是ref l_Monitor,考虑到对象是在几行之前实例化的,这是很奇怪的。有人知道为什么会发生吗?请注意,我在代码的其他地方也看到了相同的问题。
IDMS.Monitor l_Monitor = new IDMS.Monitor(); l_Monitor.LogFile.Product_ID = "SE_WEB_APP"; if (m_PermType_RadioButtonList.SelectedIndex == -1) { l_Monitor.LogFile.Log( Nortel.IS.IDMS.LogFile.MessageTypes.ERROR, "No permission type selected" ); return; } bool l_Success = SE.UI.Utilities.GetPermissionList( ref l_Monitor, ref m_CPermissions_ListBox, (int)this.ViewState["m_Account_Share_ID"], (m_PermFolders_DropDownList.Enabled) ? m_PermFolders_DropDownList.SelectedItem.Value : "-1", (SE.Types.PermissionType)m_PermType_RadioButtonList.SelectedIndex, (SE.Types.PermissionResource)m_PermResource_RadioButtonList.SelectedIndex);
解决方案
回答
我们确定尝试在l_Monitor实例上访问的属性之一不为null吗?
回答
暂时在该行(loooooongg)上为所有属性查询添加一些变量。运行调试器,检查值并转入小错误。
回答
我倾向于同意其他人的观点。听起来我们正在传递的参数之一SE.UI.Utilities.GetPermissionList为null,这会导致异常。最好的选择是启动调试器,并检查变量是否在调用该代码之前。
回答
实际上,NullReferenceException
是抛出在catch块中的,因此堆栈跟踪无法显示该行代码,因此它在调用者处停止。
它确实是l_Monitor实例的属性之一。