Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Runtime.Remoting.Channels.CoreChannel.GetMachineIP() from .NET Reflector - please explain

Tags:

.net

Using .Net Reflector on System.Runtime.Remoting.Channels.CoreChannel I decompiled the 2 methods below. GetMachineIp() is called when setting up an HttpChannel for remoting.

internal static string GetMachineIp()
{
    if (s_MachineIp == null)
    {
        IPHostEntry hostEntry = Dns.GetHostEntry(GetMachineName());
        AddressFamily addressFamily = Socket.SupportsIPv4 ? 
            AddressFamily.InterNetwork : AddressFamily.InterNetworkV6;
        IPAddress machineAddress = GetMachineAddress(hostEntry, addressFamily);
        if (machineAddress != null)
        {
           s_MachineIp = machineAddress.ToString();
        }
        if (s_MachineIp == null)
        {
            throw new ArgumentNullException("ip");
        }
}
return s_MachineIp;

}

internal static string GetMachineName()
{
    if (s_MachineName == null)
    {
        string hostName = GetHostName();
        if (hostName != null)
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(hostName);
            if (hostEntry != null)
            {
                s_MachineName = hostEntry.HostName;
            }
        }
        if (s_MachineName == null)
        {
            throw new ArgumentNullException("machine");
        }
    }
    return s_MachineName;

}

My question is why would Dns.GetHostEntry() in GetMachineIP() fail with SocketException "No such host is known". GetMachineName() returns successfully (which also does a GetHostEntry). This is only happening on an isolated machine. Could it be something to do with incorrect DNS registration?

like image 384
Kevin Avatar asked Nov 06 '22 11:11

Kevin


2 Answers

Check out the comments in this MSDN documentation:

http://msdn.microsoft.com/en-us/library/ms143998.aspx

It says that you need a forward host/A entry in the DNS for the machine. Another entry says that this has changed in version 4.0. So maybe you can try .NET Framework 4.0 and see if it solves your problem. If not check your DNS registration for the machine.

Hope that helps!

like image 184
aKzenT Avatar answered Nov 15 '22 12:11

aKzenT


I probably encountered the same issue: Setting up a .NET Remoting HttpChannel failed with the "No such host is known" exception on an isolated machine.

The name of the machine turned out to be the cause. GetMachineName returned "12", which then got interpreted as an IP address by Dns.GetHostEntry. Changing the computer name resolved the issue.

You'll have the error for computer names which can be interpreted as IP addresses by IPAddress.Parse

like image 24
wdem Avatar answered Nov 15 '22 12:11

wdem