0

I was directed to SuperUser from a question I posted on stack overflow.

Link to StackOverflow question: New Instance of TCPClient Exception

While creating an application on Visual Studios 2013 professional on a windows 7 machine using C# WinForms, I came across an exception. The Exception reads:

An invalid argument was supplied.

I even used a simple Console Application to demonstrate the issue. The line of code that creates the issue is as follows:

TcpClient tcpClient = new TcpClient();

The stack trace that I get for this is as follows:

"at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)\r\n at System.Net.Sockets.TcpClient.initialize()\r\n at System.Net.Sockets.TcpClient..ctor(AddressFamily family)\r\n at System.Net.Sockets.TcpClient..ctor()\r\n at ConnectLite.ConnectLite.MakeConnection() in h:\Howard\Projects\ConnectLite\ConnectLite\Form1.cs:line 120"

More about the issue:

This exception/error only happens on my workstation/computer. When running this application that I have created on other computers, one with and one without VisualStudios '13, I do not receive the error/exception and the application gets further into the code.

My assumption is that there is some sort of internal corruption, error, or bug. Someone on StackOverflow suggested that there might be an issue with the .NET framework. I really have no idea. I have finally reached the assumption that the issue does not lie with the coding/C#. Others on StackOverflow have ran my simple console application (all that is in the console app is the single line declaring a new TcpClient). Upon doing this, the others on StackOverflow did not receive any errors or exceptions.

Does anyone have any ideas about this issue?

I will be monitoring this feed regularly. All questions, tips, hints, and answers are welcome.

Community
  • 1
  • 1
RHoward78
  • 53
  • 1
  • 9
  • what version of .NET are you using? what version are other machines using that you tested this on? – Russell Uhl Jun 11 '15 at 17:43
  • @RussellUhl The computers are running with .NET framework v4.5.1 – RHoward78 Jun 11 '15 at 18:32
  • it really seems like it doesn't want you callling the default constructor. have you tried setting the server/port as you are initializing the TCPClient object? – Frank Thomas Jun 11 '15 at 19:14
  • Yes sir. I have tried the following: `tcpClient = new TcpClient(family); tcpClient = new TcpClient(clientIPAddress, clientPortNumber); tcpClient = new TcpClient(remoteEP); tcpClient = new TcpClient(localEP);` Note, TcpClient was declared globally. In the console app, I simply tested the zero arg constructor. but in my winforms app, I tried everything. – RHoward78 Jun 11 '15 at 20:40
  • One way to investigate this further might be to use [Winsock Tracing](https://msdn.microsoft.com/en-us/library/windows/desktop/bb892103.aspx). A trace on your failing system might provide more detail about the failure. If not then comparing traces from a working system and your failing system might tell you something. – Frank Boyne Jun 11 '15 at 20:41
  • @FrankBoyne Thank you, reading on this now. Will comment after. – RHoward78 Jun 11 '15 at 20:50
  • I should perhaps have also suggested some more simple tests. Does _any_ networking work on your failing system? For example can you run a browser on the system and access a web site? Can you run the telnet client on the system and connect somewhere? – Frank Boyne Jun 11 '15 at 20:55
  • @FrankBoyne The machine that throws the exception is connected and working on a network. In fact, it is this one that I am currently using to open numerous pages through google to find the problem haha. I have pinged local host and it works. – RHoward78 Jun 11 '15 at 21:38
  • @FrankBoyne I am not familiar with the telnet client – RHoward78 Jun 11 '15 at 21:39
  • The Telnet client is a simple Windows command-line program that implements the Telnet protocol. It's sometimes useful for very basic IP network testing. For example `telnet an.example.com 1234` will attempt to connect to port 1234 on host an.example.com. Of course what happens then depends on what's on the other end. But it is a quick and dirty way of attempting a network connection without much effort. But perhaps not necessary at this point. – Frank Boyne Jun 11 '15 at 23:46
  • Another experiment you might perform would be to create a Native C++ program that creates a socket to see if that also fails. Following the instructions in [Creating a Basic Winsock Application](https://msdn.microsoft.com/en-us/library/windows/desktop/ms737629.aspx); [Initializing Winsock](https://msdn.microsoft.com/en-us/library/windows/desktop/ms738566.aspx) and [Creating a Socket for the Client](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530741.aspx) should get you to the same point as your .NET program seems to get to when it fails (albeit with different parameter values) – Frank Boyne Jun 11 '15 at 23:50

1 Answers1

0

With help from those in Stack Overflow, I have located the fix to my problem. See: Answer to Issue

The problem was simple. I had my files stored on a network drive location. I moved these files to the documents folder and stored them locally and the problem was resolved. Thank you all for your input!

It is always bittersweet when the issue is fixed with a simple solution that you knew better then to forget.

Community
  • 1
  • 1
RHoward78
  • 53
  • 1
  • 9