Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:44:48+00:00 2026-06-13T04:44:48+00:00

I have the following .NET code. Most of it was written long before I

  • 0

I have the following .NET code. Most of it was written long before I was hired, and none of the original devs still work for us.

private void SendTCPMessage(string IpAddress, string Message)
    {
        ...

        //original code that fails because the Host entry produced 
        //has no elements in AddressList.
        //IPHostEntry remoteMachineInfo = Dns.GetHostEntry(IpAddress);

        //New code that fails when connecting
        IPHostEntry remoteMachineInfo;

        try
        {
            remoteMachineInfo = Dns.GetHostEntry(IpAddress);

            if (remoteMachineInfo.AddressList.Length == 0)
               remoteMachineInfo.AddressList = 
                  new[]
                     {
                        new IPAddress(
                           //Parse the string into the byte array needed by the constructor;
                           //I double-checked that the correct address is produced
                           IpAddress.Split('.')
                           .Select(s => byte.Parse(s))
                           .ToArray())
                     };
        }
        catch (Exception)
        {
            //caught and displayed in a status textbox
            throw new Exception(String.Format("Could not resolve or parse remote host {0} into valid IP address", IpAddress));
        }

        socketClient.Connect(remoteMachineInfo, 12345, ProtocolType.Tcp);

        ...
    }

The SocketClient code of note is as follows:

    public void Connect(IPHostEntry serverHostEntry, int serverPort, ProtocolType socketProtocol)
    {
        //this line was causing the original error; 
        //now AddressList always has at least one element.
        m_serverAddress = serverHostEntry.AddressList[0];
        m_serverPort = serverPort;
        m_socketProtocol = socketProtocol;
        Connect();
    }

    ...

    public void Connect()
    {
        try
        {
            Disconnect();
            SocketConnect();
        }
        catch (Exception exception) ...
    }

    ...

    private void SocketConnect()
    {
        try
        {
            if (SetupLocalSocket())
            {
                IPEndPoint serverEndpoint = new IPEndPoint(m_serverAddress, m_serverPort);

                //This line is the new point of failure
                socket.Connect(serverEndpoint); 

                ...
            }
            else
            {
                throw new Exception("Could not connect!");
            }
        }
        ...
        catch (SocketException se)
        {
            throw new Exception(se.Message);
        }
        ...
    }

    ...

    private bool SetupLocalSocket()
    {
        bool return_value = false;
        try
        {
            IPEndPoint myEndpoint = new IPEndPoint(m_localAddress, 0);
            socket = new Socket(myEndpoint.Address.AddressFamily, SocketType.Stream, m_socketProtocol);
            return_value = true;
        }
        catch (SocketException)
        {
            return_value = false;
        }
        catch (Exception)
        {
            return_value = false;
        }
        return return_value;
    }

When connecting to the endpoint within SocketConnect, I get a SocketException stating:

The system detected an invalid pointer address in attempting to use a pointer argument in a call.

Information online is a bit light on how to fix this. AFAICT, the address is parsing properly, and it’s retrieved properly once passed in to the SocketClient class. Honestly, I don’t know if this code has ever worked; I have never personally seen it do what it’s supposed to, and the functionality that uses all this was created for the benefit of a single client of ours, and has apparently not been functional since before I was hired.

I need to know what to look for to resolve the error. If it helps, the remote computer to which I am trying to establish a connection is on the remote side of a VPN tunnel, and we do have connectivity via other pieces of software we use.

Help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:44:49+00:00Added an answer on June 13, 2026 at 4:44 am

    Found it. The address used as the local endpoint for the socket, in SetupLocalSocket(), used a similarly naive method of getting the address; by resolving the local host and getting the first address. That first address, more often than not, is an IPv6 address, not the IPv4 address that was obviously expected. So, I had it look for the first IPv4 address in the list and use that as the endpoint, and it worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anything I have tried didn't work. Currenly I have following code to change asp.net
I have the following VB.NET code (but for each loops are in most languages,
I have following asp.net code but it gives error when I change dropdown selected
I have following code that I am compiling in a .NET 4.0 project namespace
I have the following code setup: http://jsfiddle.net/bABHU/2/ Had to change it a little bit
I have the following code in my ASP.NET project public sealed class IoC {
I have the following code in a full .NET framework solution: public delegate int
i have the following code in an asp.net mvc view. <% = Html.DropDownList(Filter, new
I have the following code: http://jsfiddle.net/uRCL2/1 At the moment the result is shown in
I have the following code in a ASP.NET master page: <div id=hyperlinkimage><asp:HyperLink ID=SomeHyperLink runat=Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.