Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Net.IPAddress.Address' is obsolete

Tags:

c#

ip-address

I try to convert Ip Address to uint:

IPAddress requstedIpAddress;
uint requesteIpAddressUint = (uint)IPAddress.Parse(requstedIpAddress.ToString()).Address;

And got this warning:

'System.Net.IPAddress.Address' is obsolete: 'This property has been deprecated. It is address family dependent. Please use IPAddress.Equals method to perform comparisons.

What does it mean and should i use some other way to do that ?

like image 686
mark yer Avatar asked Oct 03 '15 06:10

mark yer


1 Answers

The deprecation warning tells you that in the next update of your library which has IPAddress defined, will no longer have IPAddress.Address as a property. So your code will fail to compile after the next update to the library.

If you go to the documentation for IPAddress.Address it notes that the property is obsolete and should instead use IPAddress.GetAddressBytes.

The deprecation of IPAddress.Address is due to the adoption of IPv6 which is 128 bits while C# type long, which is actually a System.Int64, is only 64 bits.

like image 67
Nadir Muzaffar Avatar answered Oct 13 '22 21:10

Nadir Muzaffar