C# VS.NET 2003 : System.Net.IpAddress.IpAddress Obsolete

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mr Gray
    New Member
    • Apr 2008
    • 47

    C# VS.NET 2003 : System.Net.IpAddress.IpAddress Obsolete

    Hello,

    I am trying to find a newer way of implementing the following but I am unsuccessful thus far:

    Code:
    		private void SetDataPort(IPEndPoint ep)
    		{			
    			byte[] hostBytes = BitConverter.GetBytes(ep.Address.Address);
    
    .......
    At the moment I am getting the following error message:

    Code:
    'System.Net.IPAddress.Address' is obsolete: 'IPAddress.Address is address family dependant, use Equals method for comparison.'
    Any ideas of the correct way of doing this?

    Thanks.
  • Mr Gray
    New Member
    • Apr 2008
    • 47

    #2
    This method seems to have fixed my issue:

    Code:
    			IPAddress ip = ep.Address;
    			string s = ip.ToString();
    			long Address = Convert.ToInt64(s);
    			byte[] hostBytes = BitConverter.GetBytes(Address);
    Thanks.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      Seems like it would be less work to just do this?
      Code:
      System.Net.IPAddress ip = ep.Address;
      byte[] hostBytes = ip.GetAddressBytes();
      or even
      Code:
      byte[] hostBytes = ep.Address.GetAddressBytes();

      Comment

      Working...