System.Net.Sockets.Socket threw an exception

Discussion in 'Microsoft C# .NET' started by Aero, Apr 3, 2006.

  1. Aero

    Aero Guest

    Hi,
    My window application written in C# is throwing following exception
    while connecting to one FTP location

    The type initializer for System.Net.Sockets.Socket threw an exception

    This exe is working fine on staging environment, (Window 2003) but
    after migrating to production environment (Windows 2000), throwing this
    exception at

    _clientSocket = new
    Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);

    - Only three Network cards are installed on production server
    - while checking TCP/IP port status , there were few connections at
    TIME_WAIT mode. but this might not be the cause for insufficient buffer
    space.
    - Recenetly we have installed Microsoft.Net\Framework\v1.1.4322

    If somehow this is related to buffer space/long que, then how to clear
    this and manage for future.

    Not getting any idea from where to start. Any idea/suggestion would be
    of great help.

    Thanks
     
    Aero, Apr 3, 2006
    #1
    1. Advertisements

  2. Aero <> wrote:
    > My window application written in C# is throwing following exception
    > while connecting to one FTP location
    >
    > The type initializer for System.Net.Sockets.Socket threw an exception


    Have you looked at the inner exception of that exception? It should
    give more details about what went wrong.

    It's very worrying if the type initializer threw an exception though -
    that suggests that something is pretty wrong on the machine. (In
    particular, it's unlikely to be anything to do with your code.)

    Could you post a short but complete program which demonstrates the
    problem?

    See http://www.pobox.com/~skeet/csharp/complete.html for details of
    what I mean by that.

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too
     
    Jon Skeet [C# MVP], Apr 3, 2006
    #2
    1. Advertisements

  3. Aero

    Aero Guest

    Following is the code snippet which is causing the problem.
    public void Login()
    {
    try
    {
    _clientSocket = new
    Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
    -----Error Point
    }
    catch(Exception Ex)
    {
    throw new IOException("Message: " + Ex.Message+ "Source:" + Ex.Source+
    "Inner Exception" + Ex.InnerException);
    }
    IPEndPoint remoteEndPoint = new
    IPEndPoint(Dns.Resolve(_remoteHost).AddressList[0], _remotePort);

    try
    {
    _clientSocket.Connect(remoteEndPoint);
    }
    catch(Exception)
    {
    throw new IOException("Couldn't connect to remote server");
    }
     
    Aero, Apr 3, 2006
    #3
  4. Aero <> wrote:
    > Following is the code snippet which is causing the problem.


    Rather than a snippet, could you post a short but *complete* program
    which demonstrates the problem?

    Also, what is the inner exception in this case, if any?

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too
     
    Jon Skeet [C# MVP], Apr 3, 2006
    #4
  5. Aero

    Aero Guest

    Actually Code is too big but i am getting the error at
    Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);


    Error Message: The type initializer for "Syetem.Net.Sockets.Socket"
    threw an exception
    Error Source: System.Net.Sockets.SocketException
    Inner Exception An operation on a socket sould not be
    performed because the system lacked sufficient buffer space or because
    a queue was full
    at System.Net.Sockets.Socket.InitializeSockets()
    at System.Net.Sockets.Socket..cctor()

    Please refer the following Microsoft article
    FIX: Socket initialization does not succeed if your computer has more
    than 50 network bound protocols
    http://support.microsoft.com/?id=826757

    Now we are planning to upgrade to Microsoft.Net Framework 2.0 on
    production environment and lets see if it works or not.

    Please suggest what can we do resolve this ASAP, even we are not sure
    that will that work or not....just taking a chance.
     
    Aero, Apr 4, 2006
    #5
  6. Aero <> wrote:
    > Actually Code is too big but i am getting the error at
    > Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);


    The existing code may be too big, but have you tried creating a sample
    program just for the sake of pinning down the error?

    > Error Message: The type initializer for "Syetem.Net.Sockets.Socket"
    > threw an exception
    > Error Source: System.Net.Sockets.SocketException
    > Inner Exception An operation on a socket sould not be
    > performed because the system lacked sufficient buffer space or because
    > a queue was full
    > at System.Net.Sockets.Socket.InitializeSockets()
    > at System.Net.Sockets.Socket..cctor()
    >
    > Please refer the following Microsoft article
    > FIX: Socket initialization does not succeed if your computer has more
    > than 50 network bound protocols
    > http://support.microsoft.com/?id=826757
    >
    > Now we are planning to upgrade to Microsoft.Net Framework 2.0 on
    > production environment and lets see if it works or not.
    >
    > Please suggest what can we do resolve this ASAP, even we are not sure
    > that will that work or not....just taking a chance.


    Well, have you read the article it referenced?

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
    If replying to the group, please do not mail me too
     
    Jon Skeet [C# MVP], Apr 4, 2006
    #6
  7. Aero

    Aero Guest

    Hi,
    I am not able to simulate this problem in any of our environments. This
    is occuring only on production server.
    I tried a sample code there and again it gave the same error.
    While investigating we found that production server has .Net framework
    1.1.4322 installed without service pack 1.
    Now we are assuming that this might be the problem and today we are
    going to upgrade this to .Net Framework 2.0.50215
    Lets see what happens. If it works fine then its OK otherwise i'll have
    think in different direction.
    Thanks for your valuable inputs.
     
    Aero, Apr 6, 2006
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin
    Replies:
    1
    Views:
    1,377
    Jon Skeet
    Aug 30, 2003
  2. Rich Blum
    Replies:
    2
    Views:
    199
    Robert A. van Ginkel
    Sep 10, 2003
  3. Tony Caduto

    Inheriting from System.Net.Sockets.Socket problems.

    Tony Caduto, Aug 17, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    178
    Guest
    Aug 17, 2004
  4. Guest

    System.Net.Sockets.Socket closing prematurly

    Guest, May 20, 2005, in forum: Microsoft C# .NET
    Replies:
    3
    Views:
    169
    Feroze [msft]
    May 21, 2005
  5. Claire
    Replies:
    1
    Views:
    556
    Guest
    Aug 2, 2005
Loading...

Share This Page