Solved

Dns.GetHostEntry(string.Empty).HostName failing

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now