title: How to Serialize CookieContainer in wp7 applications?
body: <p>I tried to Serialize cookie to save it and Deserialize at next time I start my application.But the result of Deserialize is empty.What's wrong?</p>
  
  <pre><code>void SaveCookie() {
      var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
      if (this.checkBox_save_passowrd.IsChecked == true)
      {
          CookieContainer cc = SEC_Services.Httprequest.cookie;
          string fileName = "usercookie.xml";
          using (var file = appStorage.OpenFile(fileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write))
          {
              using (var writer = new StreamWriter(file))
              {
                  System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(CookieContainer));
                  xs.Serialize(writer, cc);
                  writer.Close();
              }
          }
      }
      else {
          if (appStorage.FileExists("usercookie.xml"))
          {
              appStorage.DeleteFile("usercookie.xml");
          }
      }
  }
  
  void ReadCookie() {
      var appStorage = IsolatedStorageFile.GetUserStoreForApplication();
      if (appStorage.FileExists("usercookie.xml"))
      {
          using (System.IO.StreamReader reader = new StreamReader(appStorage.OpenFile("usercookie.xml", FileMode.Open)))
          {
              System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(CookieContainer));
              CookieContainer obj = (CookieContainer)xs.Deserialize(reader);
              reader.Close();
              SEC_Services.Httprequest.cookie = obj;
              if (obj.Count != 0) {
                  NavigationService.Navigate(new Uri("/PanoramaPage.xaml", UriKind.Relative));
              }
          }
      }
  }
  </code></pre>
  
  <p>I also found this simple
  <a href="https://stackoverflow.com/questions/1777203/c-writing-a-cookiecontainer-to-disk-and-loading-back-in-for-use">C#: Writing a CookieContainer to Disk and Loading Back In For Use</a>
  shows that CookieContainer could be Serialize.But there is no <code>SoapFormatter</code> in wp7 library</p>