2

So I'm trying to work through the Catel 'getting started' examples here:

https://catelproject.atlassian.net/wiki/display/CTL/Getting+started+with+WPF

But I'm getting some errors in visual studio on step 3 (Serializing data from/to disk) - https://catelproject.atlassian.net/wiki/pages/viewpage.action?pageId=15630363

I create a 'top container' model called 'Settings' and a 'child class' of this called 'Global' (pretty much exactly the same as the tutorial except for less properties and different model names).

I create an interface based on the example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using App.Models;

namespace App.Services.Interfaces
{
    public interface IGlobalService
    {
        IEnumerable<Global> LoadGlobals();
        void SaveGlobals(IEnumerable<Global> globals);
    }
}

Then I create the service implementation:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using Catel.Collections;
using Catel.Data;
using App.Models;
using App.Services.Interfaces;

namespace App.Services
{
    public class GlobalService : IGlobalService
    {
        private readonly string _path;

        public GlobalService()
        {
            string directory = Catel.IO.Path.GetApplicationDataDirectory("CatenaLogic", "WPF.GettingStarted");

            _path = Path.Combine(directory, "global.xml");
        }

        public IEnumerable<Global> LoadGlobals()
        {
            if (!File.Exists(_path))
            {
                return new Global[] { };
            }

            using (var fileStream = File.Open(_path, FileMode.Open))
            {
                var settings = Settings.Load(fileStream, SerializationMode.Xml);
                return settings.Globals;
            }
        }

        public void SaveGlobals(IEnumerable<Global> globals)
        {
            var settings = new Settings();
            settings.Globals.ReplaceRange(globals);
            settings.Save(_path, SerializationMode.Xml);
        }
    }
} 

Visual studio then throws 2 errors and a warning:

Error CS0619 'SavableModelBase.Load(Stream, SerializationMode)' is obsolete: 'Please use Load(Stream, SerializationMode, ISerializationConfiguration) instead. Will be removed in version 5.0.0.'

Error CS0619 'SavableModelBase.Save(string, SerializationMode)' is obsolete: 'Please use Save(string, SerializationMode, ISerializationConfiguration) instead. Will be removed in version 5.0.0.'

Warning CS0618 'CollectionExtensions.ReplaceRange(ObservableCollection, IEnumerable)' is obsolete: 'Please use ReplaceRange(this ICollection<T>, IEnumerable<T>) instead. Will be treated as an error from version 5.0.0. Will be removed in version 5.0.0.'

So far all research I have done on this has come up blank. What is 'ISerializationConfiguration' and how do I implement it? Am I missing something obvious?

Setup is:

  • Visual Studio 2015 Community (14.0.25425.01 Update 3)
  • Project targeting .NET 4.5.2
  • Project initialized using New > Online > WPF application using Catel
  • NuGet:
    • Catel.Core 4.5.3
    • Catel.Extensions.Controls 4.5.3
    • Catel.MVVM 4.5.3
    • Catel.Fody 2.14.0

Any help would be much appreciated.

Asnivor
  • 266
  • 1
  • 8

1 Answers1

0

Use the overload as specified by the error / warning:

Load(stream, null);
Save(stream, null);
Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32