Link to home
Start Free TrialLog in
Avatar of deshaw
deshawFlag for India

asked on

Dns.GetHostEntry(string.Empty).HostName failing

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.
Avatar of deshaw
deshaw
Flag of India image

ASKER

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.
Avatar of deshaw

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of deshaw

ASKER

Thanks but the problems was in hosts file. We have solved it in https://www.experts-exchange.com/questions/23812130/Why-GetHostEntry-behaviour-is-different.html

Avatar of deshaw

ASKER

thanks but this was not useful.