In my C#/WPF/.Net 4.5 program I'm trying to do a Disconnect() on a socket and when I do I get a
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
. . . in the Visual Studio Output window.
My code is wrapped in a try/catch but it never lands in the catch . . .
try
{
if (_TCPConn.Connected)
{
_TCPConn.Shutdown(SocketShutdown.Both);
_TCPConn.Disconnect(true); // SocketException
}
}
catch (Exception e)
{
. . .
}
Up until this point the Socket works fine - it's used to communicate with some manufacturing machinery and all that stuff works perfectly. I've tried this with and without the Shutdown() with the same results. If I let my program keep running after the first chance exception the whole program just disappears and exits the debugger. Then the message in the Output window just says
The program '[0xE6C] ProcFacTest.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
How do I figure out what's causing this?
The first step is to disable "Just My Code". This probably shouldn't be necessary but it's possible the IDE is confusing your user code with system code and suppressing the exception as a result. I generally do this when doing exception debugging
The next step is to tell Visual Studio to break when that particular exception is thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With