Solved

Dns.GetHostEntry(string.Empty).HostName failing

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error on Add method 1 50
Connection String 16 54
Coding C# in Linux 8 61
transaction in asp.net, sql server 6 31
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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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