【问题标题】:Null check and then Null ref Exception in C#空值检查,然后是 C# 中的空值引用异常
【发布时间】:2013-07-10 02:00:26
【问题描述】:
Line1: if( m_Action != null )
Line2:     m_Action();    // Null ref Exception!!
  • m_Action 是 C# 中的 Action 类。
  • m_Action 在构造函数中初始化,然后没有改变。
  • m_Action 的方法具有多态性。
  • 这个程序是多线程的。

我认为 m_Action 表示不为空(超类的方法) 但在 Null obj(子类)中的 m_Action 方法。为什么会这样?

【问题讨论】:

  • 需要更多详细信息。
  • 第 0 行:Action m_action = () => { FooClass x = null; x.Bar(); }

标签: c# .net nullreferenceexception


【解决方案1】:

正在从 Action 中的代码中抛出空引用异常,以找出启用异常断点的位置。

Debug->Exceptions,然后检查 Thrown 列中的 Common Language Runtime Exceptions,调试器将在抛出空引用异常时停止。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-30
    • 1970-01-01
    • 2021-07-22
    • 2021-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    相关资源
    最近更新 更多