none
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) gives a SocketException "An operation was attempted on something that is not a socket" RRS feed

  • Question

  • Our code seems innocent enough - it is quite similar to the Example code regarding to HttpWebRequest, but of course, we do have a lot more other functional code beside this, but still the related code looks comparatively seperated from other logic, to simplify, the following illustrate the logic related to our code on HttpWebRequest:

     // Create a new HttpRequest
     HttpWebRequest request = WebRequest.Create(urlString) as HttpWebRequest;

     // Initialize the request - and does some logging for debugging purposes.
     request.ContentType = "application/xml";
     ...
     request.Method = "POST";

     // Getting ready to send the request body...
     // But this line sometimes gives an SocketException:
     Stream requestStream = request.GetRequestStream();

    ---> System.Net.WebException: Unable to connect to the remote server
    ---> System.Net.Sockets.SocketException: An operation was attempted on something that is not a socket xxx.xxx.xxx.xxx:80
       at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
       at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
       --- End of inner exception stack trace ---
       at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
       at System.Net.HttpWebRequest.GetRequestStream()

    To me, it looks that this is a makign a new connection to the webserver, thus I really could not understand why this Exception would be thrown.  The more frustrated issue is that this does not happen often, and we have not found a way to consistently reproduce the issue.

    I have searched online, and one article seems to indicate potentially the memory heapspace with the shared section might be too small in some older Windows platform, - but this happens on Windows 7, and when I checked, the value seems reasonable according microsoft's recommendation: 1024,20480,768.

    But as the Exception happens seems totally within the System.Net library, I can only suspect that some sharing/synchronization within the lib regarding to the Sockets/Connection might not be tight enough.

    Thursday, September 4, 2014 9:07 PM

Answers

  • Hello JoeJoe12345,

    Since we cannot reproduce this issue, what we can do is to provide some related information regarding this error:

    This issue may occur if you have a third-party product installed that uses Windows sockets and also uses the ipconfig, release, and renew commands. The Windows sockets registry subkeys may be corrupted.

    There are two methods you could try with the KB link:

    http://support.microsoft.com/kb/817571/en-gb

    This behavior may occur if the WinSocks library or the TCP/IP stack are corrupted, there are details steps for fixing it:

    http://support.microsoft.com/kb/318584/en-gb

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 8, 2014 6:55 AM
    Moderator