title: Getting no results because SocketException occurred in System.dll
body: <p>I am writing an application that retrieves the names and IP addresses of all computers on a given network. This is for technical support to use while remoting into a computer. I'm still developing and only testing on my own network, but when I run it I get no results and this shows up in the output.</p>
  
  <pre><code>A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
  </code></pre>
  
  <p>My code is as follows:</p>
  
  <pre><code>public List&lt;NetworkComputer&gt; getComputers( string domain )
          {
              List&lt;NetworkComputer&gt; computers = new List&lt;NetworkComputer&gt;();
  
              DirectoryEntry entry = new DirectoryEntry( domain );
              DirectorySearcher searcher = new DirectorySearcher( entry );
              searcher.Filter = ("(objectClass=computer)");
              searcher.SizeLimit = int.MaxValue;
              searcher.PageSize = int.MaxValue;
  
              foreach( SearchResult result in searcher.FindAll() )
              {
                  if( result.GetDirectoryEntry().Name.StartsWith( "CN=" ) )
                  {
                      IPAddress ipAddress = null;
  
                      ipAddress = Dns.GetHostAddresses( result.GetDirectoryEntry().Name.Remove( 0, "CN=".Length ) )[0];
  
                      computers.Add( new NetworkComputer( result.GetDirectoryEntry().Name.Remove( 0, "CN=".Length ), ipAddress ) );
                  }
              }
  
              return computers;
          }
      }
  }
  </code></pre>
  
  <p>If I run it without attempting to get IP addresses I get a list of all computers with no issues. It's the IP addresses that are causing me problems.</p>