I have the following method:
public bool ConnectAsync()
{
if (IsConnected)
throw new InvalidOperationException(\"Socket is already connected\");
This answer explained the problem I was having: https://stackoverflow.com/a/27552124/1830461
Something of this format compiled to 64-bit can cause the debugger to step into the if statement:
if (falseCondition)
throw new Exception();
try { } catch { }
It's a bug in Visual Studio. The code isn't actually executed. The solution is to just ignore it and continue stepping through the code. Putting a lock statement on it fixes it, because it is no longer in that format.