Why Dns.Resolve Method in C# is obsolete ? Workaround?
-
I am trying to write a small function in C# by passing this DNS name www.google.com And the function should return the host IP , it is like querying DNS server! I wrote the following program , but it seems there this Warning Warning 1 'System.Net.Dns.Resolve(string)' is obsolete: 'Resolve is obsolete for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202' D:\CoDoNS\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 26 20 WindowsFormsApplication1 Using System; Using Sytem.Net; namespace BuilderExamples { class BuilderIPAddress { static void Main(string[] args) { try { IPHostEntry iphe = Dns.Resolve("www.google.com"); foreach (IPAddress addr in iphe.AddressList) { Console.WriteLine("AddressFamily: " + addr.AddressFamily.ToString()); Console.WriteLine("Address: " + addr.ToString()); } } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); } } } } Why Dns.Resolve Method in C# is obsolete ? is the a workaround to get that function done? Thanks
-
I am trying to write a small function in C# by passing this DNS name www.google.com And the function should return the host IP , it is like querying DNS server! I wrote the following program , but it seems there this Warning Warning 1 'System.Net.Dns.Resolve(string)' is obsolete: 'Resolve is obsolete for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202' D:\CoDoNS\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 26 20 WindowsFormsApplication1 Using System; Using Sytem.Net; namespace BuilderExamples { class BuilderIPAddress { static void Main(string[] args) { try { IPHostEntry iphe = Dns.Resolve("www.google.com"); foreach (IPAddress addr in iphe.AddressList) { Console.WriteLine("AddressFamily: " + addr.AddressFamily.ToString()); Console.WriteLine("Address: " + addr.ToString()); } } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); } } } } Why Dns.Resolve Method in C# is obsolete ? is the a workaround to get that function done? Thanks
Well, the warning message is already giving you the answer. Use Dns.GetHostEntry:
IPHostEntry iphe = Dns.GetHostEntry("www.google.com");
-
Well, the warning message is already giving you the answer. Use Dns.GetHostEntry:
IPHostEntry iphe = Dns.GetHostEntry("www.google.com");
-
"Obsolete" : "No longer in use"[^] In practice, it means you should not use it for new projects; there is a better equivalent. If you do use it, be aware that future releases of the IDE may not support it, or may not support it fully. On your own head be it! Would you specify a 80386 based computer for a new project? It is obsolete too.
All those who believe in psycho kinesis, raise my hand.