Dns.GetHostByAddress works. Dns.GetHostEntry fails. why?

S

Steve Richter

I am using Dns.GetHostByAddress and Dns.Resolve to successfully
resolve and IP address to an IPEndPoint.

IPEndPoint ep = null;
IPAddress ipAddr = IPAddress.Parse(m_sRemoteHost);
ep = new IPEndPoint(Dns.GetHostByAddress(ipAddr).AddressList[0],
m_iRemotePort);
// ep = new IPEndPoint(Dns.GetHostEntry(ipAddr).AddressList[0],
m_iRemotePort);
// ep = new IPEndPoint(Dns.Resolve(m_sRemoteHost).AddressList[0],
m_iRemotePort);

but the compiler complains, saying these methods are obsolete and are
replaced by GetHostEntry. When I use the GetHostEntry method the code
fails with an "no such host is known" exception.

Why would GetHostByAddress succeed and GetHostEntry fail?

thanks,

-Steve
 
P

Peter Duniho

Steve Richter said:
[...]
Why would GetHostByAddress succeed and GetHostEntry fail?

I don't know, but this has come up before, and someone's even posted a
comment to the docs for GetHostEntry() pointing out the problem:
http://msdn2.microsoft.com/en-us/library/ms143998.aspx

I haven't had the same problem myself, but I also haven't seen any
indication that people who do have the problem are misusing GetHostEntry(),
and so I would say that following the advice in the comments for the method,
to use the "obsolete" methods instead, may be good advice.

Pete
 
P

Peter Duniho

Steve Richter said:
wow. thanks a lot. I had checked in MSDN but did not see this.

You have to look at the v3.0 docs for the method.

I suppose there's some value to the way that MSDN breaks out the 1.1, 2.0,
and 3.0 versions of the documentation. But a) there's a lot of examples of
that where the documentation is basically identical across each version, and
b) even when the documentation is different certain things remain the same,
and it would be much better if there were a way to consolidate that
information in one place.

The search tool doesn't help much either, since it returns a wide variety of
similar pages, all with these subtle differences, and without any clear
rhyme or reason behind which page is first on the results list of the
search.

Oh well...anyway, that's a long way of saying that if you didn't see the
issue described when you first looked at the documentation, it's not
necessarily because you just didn't scroll down far enough. It might not
have actually been on the page you looked at. :(

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top