-1

I wrote code that overrides object's Equals. I realized, after I wrote it, that I'm going to have StackOverFlowException since I didn't yet implemented the IEquatable interface to handle the last line of code. Yet, I run the code to see what happen, and some strange thing happen, you can see for yourself in the following image:

enter image description here

The breakpoint isn't even hittable at this moment, seems like the code is being used even before my program is run. Is it something that is done by the CLR ? Is it something else ?

Thanks for the help !

6
  • 1
    Your brakepoint will never be hit. It's white inside (not red and have warning on it), so the code does not match the running probram. Rebuild your solution. Commented May 11, 2016 at 6:49
  • Did you implement IEquatable<T> interface? Commented May 11, 2016 at 7:35
  • Take a look at this one might helps recursive depth Commented May 11, 2016 at 8:12
  • @Dovydas Sopa - it isn't the problem, it is after a build. Commented May 11, 2016 at 9:33
  • @Alessandro D'Andria - Yes, you're right, fixed it. thanks Commented May 11, 2016 at 9:37

1 Answer 1

2

The stack is exhausted (the very last straw that breaks camel's back) on

  if (ReferenceEquals(right, null))

probably, the stack doesn't have another 4 (8) bytes to store right. The actual reason seems to be at

  return Equals(right as Quality)

if right is of Quality type, the code is doomed to call Equals again and again

Sign up to request clarification or add additional context in comments.

3 Comments

I know where the recursive part is, it can be shown by the mark next to that line. This isn't my question. The question is why the breakpoint was missed. I would expect that even if it is an endless recursive function, I would hit the breakpoint in the first call to Equals.
@Moti Berger: the stack is consuming, and in some point it, finally, got exhausted: stack can't allocate another 4/8 bytes. This final blow can occur at some random/weird point
I understand that in an infinite recursive calling the stack eventually get exhausted, but for the exhaustion to happen, the function's code must run at least one time, so why the breakpoint wasn't hit. Something, which isn't my code, must have used the Equals function of the Quality type before my code even run ! My question is who used that function. The program crashed before it starts !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.