C# object serialization in wpf RRS feed

  • Question

  • How to serialize a c# class if can't mark base class as Serializable.

    I am using Caliburn Micro in c# wpf application and MyViewModel is derived from Screen (https://caliburnmicro.com/documentation/composition). I need to serialize (Xml serializer / BinarySerializer / DataContractSerializer) object of MyViewModel in a file so that I can use it later.

    I can mark MyViewModel as [Serializable] but getting exception that base class (which is Screen from caliburn micro) is not marked as [Serializable] so can't serialize object. I can't add attribute as [Serializable] in Screen because its a third party library.

    Can anyone suggest me how to serialize MyViewModel object ?

    [Serializable] public class MyViewModel : Screen { // Rest of functionalities }

    I am getting the exception : Type 'Caliburn.Micro.Screen' in Assembly 'Caliburn.Micro, Version=, Culture=neutral, PublicKeyToken=1f2ed21f' is not marked as serializable. 

    Thursday, August 8, 2019 8:48 PM