I am trying to serialize the project, but all the time I get an exception when reading a line

[DataContract] public class ImageManipulatorViewModel : BaseViewModel { [DataMember] public ObservableCollection<Collage> ImageList { get { return this.imageList; } set { this.imageList = value; base.RaisePropertyChanged("ImageList"); } } var storageFolder = ApplicationData.Current.LocalFolder; var sampleFile = await storageFolder.CreateFileAsync("MyProject.Collage", CreationCollisionOption.ReplaceExisting); string l =JsonConvert.SerializeObject(this.ImageList); аwait FileIO.WriteTextAsync(sampleFile, l); string tres = JsonConvert.DeserializeObject(l).ToString(); this.ImageList.Clear(); this.ImageList = JsonConvert.DeserializeObject<ObservableCollection<Collage>>(tres.ToString()); } public class Collage { public Thickness Position { get; set; } public WriteableBitmap Image { get; set; } } 

I get this error

 Сould not create an instance of type Windows.Storage.Streams.IBuffer. Type is an interface or abstract class and cannot be instantiated. Path '[0].Image.PixelBuffer', line 10, position 23. 

    1 answer 1

    Firstly, the WriteableBitmap not serialized, therefore it was replaced with the URI . Secondly, the ObservableCollection<Т> needs to be converted to a List<T>

    The code will be next

      var file = await savePicker.PickSaveFileAsync(); var ser = JsonConvert.SerializeObject(this.ImageList.ToList()); await FileIO.WriteTextAsync(file, ser);