Missing OpenStreamForWriteAsync on my StorageFile
I have a sample that I use when serializing data in order to save it to a StorageFile in Windows 8 and Windows Phone 8. It looks a little something (or exactly) like this:
StorageFile kittenFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("Kittens4Ever.kittens", CreationCollisionOption.ReplaceExisting); var writeStream = await kittenFile.OpenStreamForWriteAsync(); DataContractSerializer kittenSerial = new DataContractSerializer(typeof(ObservableCollection<Kitten>)); kittenSerial.WriteObject(writeStream, listOfKittens); await writeStream.FlushAsync(); writeStream.Close();
But I keep running into this problem where my StorageFile doesn’t have the OpenStreamForWriteAsync method available. After yelling and cursing and bing-ing the problem for a while, I realize the solution:
OpenStreamForWriterAsync (and OpenStreaForReadAsync) are extension methods that require System.IO to be added as a reference. So I just add it
and everything works fine.