title: New Instance of TCPClient Exception
body: <p>I asked a similar question to this a few days ago.  At that point, I was trying to use sockets.  Currently, I am using TCPClient to do the dirty socket work for me.  I am using Windows 7 and Visual studios 2013 Professional.</p>
  
  <p>Original and Current Project Outline:</p>
  
  <p>I need to create an application (WinForms using C#) that allows the user to connect to a device (a piece of hardware that will be sent arguments/commands) via wifi (wifi is end goal but I am settling at the moment for any connection) and then send messages to said device. I know some C# and some sockets/IP stuff, but not sockets/IP using C#. The visual, GUI side of the program is not what I am struggling with. I cannot seem to get the TCPClient up and running and make any real connection. I keep getting the "An Invalid Argument was Supplied" exception.</p>
  
  <p>Any tips on this particular issue or help with C# networking/TCPClient/etc. are welcome.</p>
  
  <p>I have tried to create a new TcpClient each of the following ways without success:</p>
  
  <pre><code>TcpClient tcpClient = new TcpClient();
  TcpClient tcpClient = new TcpClient(family); // family is a created AddressFamily
  TcpClient tcpClient = new TcpClient(clientIPAddress, clientPortNumber);
  TcpClient tcpClient = new TcpClient(remoteEP); // remoteEP is a remote end point created by me
  TcpClient tcpClient = new TcpClient(localEP); // localEP is a local end point
  </code></pre>
  
  <p>Each of these is one of the constructors within the TCPClient class.  Each of these gives me the following exception:
  <strong>An Invalid Argument was Supplied</strong></p>
  
  <p>Stack Trace: </p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>I do have all of the necessary imports and usings.</p>
  
  <p>This problem gets strange when I try to run the application on a different computer.  On separate computers, whether it be running the application without Visual Studios from the debug file, or running it on a different computer using Visual Studios 2013, the application takes me further than the exception and the exception is never thrown.  </p>
  
  <p>I am simply trying to use TCPClient to do some simple message sending.  The TCPClient, however, is preventing me from doing that.</p>
  
  <p>When I had been using sockets, it was throwing the same exception when creating a new socket.</p>
  
  <pre><code>Socket clientSocket =
  new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  </code></pre>
  
  <p>Do any of you have any insights on this matter?</p>
  
  <p>To simplify, I have put the pertinent pieces of code into a console app so as to be easily read.</p>
  
  <p>Simple block of code with issue:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Net;
  using System.Net.Sockets;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ConsoleTestConnectLite
  {
      class Program
      {
          static void Main(string[] args)
          {
              try
              {
                  TcpClient tcpClient = new TcpClient();
              }
              catch (SocketException e)
              {
                  Console.WriteLine(e.Message);
                  Console.WriteLine("Error: " + e.StackTrace);
                  Console.WriteLine(e.Message + ". Error Code: " + e.ErrorCode.ToString());
              }
          }
      }
  }
  </code></pre>
  
  <p>Console Output:</p>
  
  <pre><code>An invalid argument was supplied
  Error:    at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, Socket
  Type socketType, ProtocolType protocolType)
     at System.Net.Sockets.TcpClient.initialize()
     at System.Net.Sockets.TcpClient..ctor(AddressFamily family)
     at System.Net.Sockets.TcpClient..ctor()
     at ConsoleTestConnectLite.Program.Main(String[] args) in h:\Howard\Projects\ConsoleTestConnectLite\ConsoleTestConnectLite\Program.cs:line 17
  An invalid argument was supplied. Error Code: 10022
  Press any key to continue . . .
  </code></pre>