繁体   English   中英

NullReferenceException关于实例化的对象?

[英]NullReferenceException on instantiated 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实例的属性之一。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM