title: 'System.Net.Sockets.SocketException exception when testing with Selenium WebDriver using C#
body: <p>I'm learning Selenium WebDriver with C#.
  I'm using Firefox 50.0 and WebDriver 3.0.1 with VS 2015</p>
  
  <p>I have the following code:</p>
  
  <pre><code>System.Environment.SetEnvironmentVariable("webdriver.firefox.marionette", @"pathToDriver");
  IWebDriver driver = new FirefoxDriver();
  driver.Navigate().GoToUrl("http://www.demoqa.com");
  </code></pre>
  
  <p>Exception is thrown on the second line:</p>
  
  <blockquote>
    <p>System.Net.Sockets.SocketException was unhandled   ErrorCode=10022<br>
    HResult=-2147467259   Message=An invalid argument was supplied<br>
    NativeErrorCode=10022   Source=System   StackTrace:
           at System.Net.Sockets.Socket..ctor(AddressFamily addressFamily, SocketType socketType, ProtocolType protocolType)
           at OpenQA.Selenium.Internal.PortUtilities.FindFreePort()
           at OpenQA.Selenium.Firefox.FirefoxDriverService.CreateDefaultService()
           at OpenQA.Selenium.Firefox.FirefoxDriver..ctor(FirefoxOptions options)
           at OpenQA.Selenium.Firefox.FirefoxDriver..ctor()
           at ToolsQA.FirstTestCase.Main(String[] args) in P:\Eugene's Practice Projects\Selenium\ToolsQA\ToolsQA\FirstTestCase.cs:line 23
           at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.RunInternal(ExecutionContext
    executionContext, ContextCallback callback, Object state, Boolean
    preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean
    preserveSyncCtx)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()   InnerException:</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>