binary formatter in uwp

Error below:

An exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Private.DataContractSerialization.dll but was not handled in user code
Additional information: Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:Value' contains data of the 'http://schemas.datacontract.org/2004/07/UWPDemo:Message' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Message' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.

 

Code here:

http://www.manoli.net/csharpformat/format.aspx

namespace QuickDemo
{
    public interface IMessage
    {
        int Id { get; set; }
    }

    public class Message : IMessage
    {
        public int Id
        {
            get;
            set;
        }

        public string Name { get; set; }
    }

    public class SerializationSample
    {
        public Dictionary<int, IMessage> Data;

        public void TestRun()
        {
            byte[] content;

            // Populate data
            Data = new Dictionary<int, IMessage>();
            Data.Add(1, new Message() { Id = 100, Name = "Name 100" });

            // Define known types
            List<Type> ktypes = new List<Type>();
            ktypes.Add(typeof(Message));

            // Serialize content
            DataContractSerializer ds = new DataContractSerializer(typeof(Dictionary<int, IMessage>), ktypes);
            using (var stream = new MemoryStream())
            {
                using (var writer = XmlDictionaryWriter.CreateBinaryWriter(stream))
                {
                    ds.WriteObject(writer, Data);
                }

                content = stream.ToArray(); // Convert to bytes
            }

            // Deserialize content
            // Convert bytes back to respective type
            using (var reader = XmlDictionaryReader.CreateBinaryReader(content, XmlDictionaryReaderQuotas.Max))
            {
                var x = (Dictionary<int, IMessage>)ds.ReadObject(reader);  // Do relevant casting here.
            }
        }
    }
}