Null reference exception when viewing a value in the debugger

I override the equals function in the my class and get a zero-point exception, even though when I enter the same code in the "watch" section of the debugger, there are no exceptions.

Here is my code (something compared to ==being a string or primitive type):

return this.workOrder == i.workOrder
    && this.upi == i.upi
    && this.testName == i.testName
    && BasicFunctions.ArraysEqual(this.testTrays, i.testTrays)
    && this.supplyVoltage == i.supplyVoltage
    && this.supplyAmperage == i.supplyAmperage
    && this.commandResults == null ? i.commandResults == null : this.commandResults.Equals(i.commandResults)
    && this.id == i.id;

View from the viewport: Screenshot of my watch window with one line for each section of the return statement.  All but the supplyAmperage section are true.

Comparison commandResultsis the only thing that can lead to a null exception, and, as you can see from the code, this script should be processed by the ternary operator. Not only this, but also in those cases when it fails, it should never have reached this section, since the line should have stopped executing in the first false section. How can this happen?

Edit: ( , ArrayEquals, , )

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="ATE"
  StackTrace:
       at ATE.Network.TestLocationListener.TestClientInformation.Equals(Object obj) in C:\Users\jdudley\git\ATE\ATE\ATE\Network\TestLocationListener.cs:line 85
       at ATE.BasicFunctions.ArraysEqual[T](T[] a1, T[] a2) in C:\Users\jdudley\git\ATE\ATE\ATE\BasicFunctions.cs:line 150
       at ATE_Remote_Controller.Form1.remoteClient1_StatusUpdated(Object sender) in C:\Users\jdudley\git\ATE\ATE\ATE Remote Controller\Form1.cs:line 25
       at ATE.Network.RemoteClient.statusRead(JSONReadCallbackResult res) in C:\Users\jdudley\git\ATE\ATE\ATE\Network\RemoteClient.cs:line 153
       at ATE.Network.JSONReader.Receive(IAsyncResult ar) in C:\Users\jdudley\git\ATE\ATE\ATE\Network\JSONReader.cs:line 236
       at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
       at System.Net.ContextAwareResult.CompleteCallback(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Net.ContextAwareResult.Complete(IntPtr userToken)
       at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
       at System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
       at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
  InnerException: 
+4
1

, , ,

return this.workOrder == (i.workOrder
    && this.upi == i.upi
    && this.testName == i.testName
    && BasicFunctions.ArraysEqual(this.testTrays, i.testTrays)
    && this.supplyVoltage == i.supplyVoltage
    && this.supplyAmperage == i.supplyAmperage
    && this.commandResults == null) ? 
        i.commandResults == null : 
        (this.commandResults.Equals(i.commandResults)
        && this.id == i.id);

.

return this.workOrder == i.workOrder
    && this.upi == i.upi
    && this.testName == i.testName
    && BasicFunctions.ArraysEqual(this.testTrays, i.testTrays)
    && this.supplyVoltage == i.supplyVoltage
    && this.supplyAmperage == i.supplyAmperage
    && (this.commandResults == null ? 
        i.commandResults == null : 
        this.commandResults.Equals(i.commandResults))
    && this.id == i.id;

, - , , this.supplyAmperage == i.supplyAmperage , this.commandResults.Equals(i.commandResults), this.commandResults - null.

+7

All Articles