System.Net.Sockets.Socket threw an exception

A

Aero

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
 
J

Jon Skeet [C# MVP]

Aero said:
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.
 
A

Aero

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");
}
 
J

Jon Skeet [C# MVP]

Aero said:
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?
 
A

Aero

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.
 
J

Jon Skeet [C# MVP]

Aero said:
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?
 
A

Aero

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top