none
An invalid argument was encountered

    General discussion

  • I was trying to use my PC to communicate with another device (via a USB port) using TCP/IP. My program was written in C++/CLI, Visual Studio 2005. So, the program works fine in many computers but not this particular computer. Whenever I run the program to set up a connection between the PC and the device, an error message window will pop up: "An invalid argument was encountered." Does anyone have any idea what causes this and why so far it only happens in one of the computers I used?

    Thanks.

    xy






    Monday, September 28, 2009 6:15 PM

All replies

  • Debug your application. What line is causing this message to appear? I suspect you will actually find an invalid argument if you made the effort to look.
    Monday, September 28, 2009 6:16 PM
  • I did try to set breakpoints to find out which lines are causing the problem. That message always appears after the line that sets up a connection between the PC and the device (e.g.):client = gcnew TcpClient("127.0.0.1, 5000);
    Is that something wrong with my software or the application software for another device?
    Monday, September 28, 2009 6:44 PM
  • I did try to set breakpoints to find out which lines are causing the problem. That message always appears after the line that sets up a connection between the PC and the device (e.g.):client = gcnew TcpClient("127.0.0.1, 5000);
    Is that something wrong with my software or the application software for another device?

    Did you place this inside a try...catch construct? If so, what exception did you catch? Was this a SocketException? If so, what is the ErrorCode?
    Monday, September 28, 2009 7:21 PM
  • Post the StackTrace of the exception.

    Hans Passant.
    Monday, September 28, 2009 7:37 PM
    Moderator
  • I did (as shown below). However, no exception was invoked. The program will establish a connection with the device and then the error message popped up.

    try

    {

    m_client =

    gcnew TcpClient("127.0.0.1", 5000);

    }

     

    catch ( Exception^ e )

    {

    e = e;

    MessageBox::Show(

    "Unable to connect to the device");

    }

    Monday, September 28, 2009 7:43 PM
  • Interesting. What does the stack trace show (as suggested by Hans)?
    Monday, September 28, 2009 7:52 PM