Solved

Dns.GetHostEntry(string.Empty).HostName failing

Posted on 2008-10-13
5
1,078 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
  • 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

Suggested Solutions

Title # Comments Views Activity
What is "public object" in C#? 3 64
bound data table problem 2 32
IEnumerable<T> to a List<T> 8 37
Please explain purpose of GZIP 4 34
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

791 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