Solved

Dns.GetHostEntry(string.Empty).HostName failing

Posted on 2008-10-13
5
1,105 Views
Last Modified: 2010-07-27
Hi Experts,

I have noticed that on one of our citrix server Dns.GetHostEntry(string.Empty).HostName failing with the below error message

      Length cannot be less than zero.
     Parameter name: length
     at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)

We have deployed our application to 1000s machines including some of citrix servers and they dont have any problems with this.  I dont know why this error is occuring only one citrix server. Could you please tell me what could be wrong.

Please dont suggest anything else except solution to this problem because our application is already in production to 1000s machine and we can not change the application. There must be a some problem with machine but we dont know. If we figured out how Dns.GetHostEntry(string.Empty).HostName  works then probably we can nail down the problem.

This problem's solution definately deserves 500 points.

Thanks.
0
Comment
Question by:deshaw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 1

Author Comment

by:deshaw
ID: 22701313
Hi,

For more info. I am using this function like below:

 try {
                //The GetHostEntry method queries a DNS server for the IP address that is associated with a host name or IP address.
                //When an empty string is passed as the host name, this method returns the IPv4 addresses of the local host.
                string hostFullName = Dns.GetHostEntry(string.Empty).HostName;                
                localHostName = hostFullName.Substring(0, hostFullName.IndexOf("."));
                hostFullName = hostFullName.Substring(hostFullName.IndexOf(".") + 1);            
                localSiteName = hostFullName.Substring(0, hostFullName.IndexOf("."));
                topDomain = hostFullName.Substring(hostFullName.IndexOf(".") + 1);            
            } catch(Exception ex) {
                Globals.LogHandler.Debug("Could not retrieve local site, host and top domain names.\n" + ex.Message + "\n" + ex.StackTrace);
                MessageBox.Show("Could not retrieve local site, host and top domain names.", "UNIX Chooser",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(0);
            }

So it may possible that given error occures in SubString because GetHostEntry has not returned any value.

Thanks.
0
 
LVL 1

Author Comment

by:deshaw
ID: 22709742
Hello,
Could anyone can take up this task. It is very important for us. Now I am having only one question. Why

Console.WriteLine("The FQDN host name is : " + Dns.GetHostEntry(string.Empty).HostName); prints just host name. Actually it prints "hostname.site.domain.com" in FQDN format but we have some hosts where it gives only "hostname" and that causing the problem.

Is it related to TCP IP parameters in registry??

Thanks.
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22713771
just a thought
if you open properties for the network card and select Internet Protocol --> Properties --> Advanced --> DNS
Is there any DNS any DNS server address configuration done or any DNS Suffix present to be appended on the servers where your application is running correctly
and on the server its not running correctly are the settings same for above mentioned properties
0
 
LVL 1

Author Comment

by:deshaw
ID: 22718494
Thanks but the problems was in hosts file. We have solved it in http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_23812130.html

0
 
LVL 1

Author Closing Comment

by:deshaw
ID: 31505558
thanks but this was not useful.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question