title: Deserializing an array using SOAP
body: <p>I'm having a problem getting a SOAP service to deserialize an array of objects; its only reading in the first member of the array and nothing else. Here is my code: </p>
  
  <pre><code>public void StoreCredentials(Credentials credentials)
      {
          Credentials[] credsArray;
          var soap = new SoapFormatter();
  
          var stream = new FileStream(_path, FileMode.OpenOrCreate);
          try
          {
              credsArray = (Credentials[])soap.Deserialize(stream);
              var credsList = credsArray.ToList();
              credsList.Add(credentials);
              credsArray = credsList.ToArray();
          }
          catch (SerializationException)
          {
              credsArray = new[] {credentials};
          }
          soap.Serialize(stream, credsArray);
          stream.Close();
      }
  </code></pre>
  
  <p>I wrote a simple unit test which adds two Credentials objects to the file, the output looks correct, both sets of credentials are present, but when I run the test to add a third set to the file, the soap.Deserialize(stream) line returns an array with only one entry, even though the file its reading from contains two entries. Am I doing something wrong here? Is there a better / easier way to do this? Please help!</p>