实例化对象上出现 NullReferenceException?

发布于 2024-07-05 04:16:47 字数 1004 浏览 5 评论 0原文

这是我继承的应用程序中的一段代码,用户遇到了黄屏死机:

未将对象引用设置为对象的实例

对象引用未设置为线上

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

This is a segment of code from an app I've inherited, a user got a Yellow screen of death:

Object reference not set to an instance of an object

on the line:

bool l_Success ... 

Now I'm 95% sure the faulty argument is ref l_Monitor which is very weird considering the object is instantiated a few lines before. Anyone have a clue why it would happen? Note that I have seen the same issue pop up in other places in the code.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉生梦死 2024-07-12 04:16:47

我倾向于同意其他人的观点; 听起来您传递的参数之一 SE.UI.Utilities.GetPermissionList 为 null,这导致了异常。 最好的办法是启动调试器并在调用代码之前检查变量是否存在。

I'm inclined to agree with the others; it sounds like one of the parameters you are passing SE.UI.Utilities.GetPermissionList is null which is causing the exception. Your best bet is to fire up the debugger and check was the variables are before that code is called.

醉生梦死 2024-07-12 04:16:47

NullReferenceException 实际上是在 catch 块中抛出的,因此堆栈跟踪无法显示该行代码,因此它在调用方处停止。

它确实是 l_Monitor 实例的属性之一。

The NullReferenceException was actually thrown within a catch block so the stack trace couldn't display that line of code so instead it stopped at the caller.

It was indeed one of the properties of the l_Monitor instance.

苄①跕圉湢 2024-07-12 04:16:47

您确定尝试在 l_Monitor 实例上访问的属性之一不为空吗?

You sure that one of the properties trying to be accessed on the l_Monitor instance isn't null?

酒几许 2024-07-12 04:16:47

暂时为该(loooooongg)行上的所有属性查询添加一些变量。 运行调试器,检查值并解决小错误。

Sprinkle in a few variables for all the property-queries on that (loooooongg) line temporarily. Run the debugger, Check values and Corner the little bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文