title: Managing cookies in C# / Selenium
body: <p>I'm having trouble removing/adding cookies in Selenium.  I'm using Windows 7 and FireFox 25.0.1.  My code looks like this:</p>
  
  <pre><code>Instance = new FirefoxDriver();
  Instance.Manage().Window.Maximize();
  
  var _cookies = Instance.Manage().Cookies.AllCookies;
  Instance.Manage().Cookies.DeleteAllCookies();
  
  foreach(Cookie cookie in _cookies)
  {
      Instance.Manage().Cookies.AddCookie(cookie);
  }
  
  var _newCookies = Instance.Manage().Cookies.AllCookies; //boom
  </code></pre>
  
  <p>On that last line I get the exception "Unexpected problem getting cookies."  I've tried several variants of the above code and the same problem occurs the second time I call <code>AllCookies</code>-- even after closing and reopening the browser and calling <code>GoToUrl(mysite)</code> and re-adding the cookies (The browser was on <code>mysite</code> when I saved the cookies).</p>
  
  <p>I've checked the cookies collection before accessing it, and they all have name/value pairs.</p>
  
  <p>Has anyone managed to use the cookie API successfully in Selenium for C# or can say what I'm doing wrong?</p>