I am trying to serialize a type, for example:
public UsersPanel(UsersVM userVm) { var serialized = Serialize(userVm); } public static string Serialize(ViewModelBase instance) { var formatter = new BinaryFormatter(); using (var stream = new MemoryStream()) { formatter.Serialize(stream, instance);
Where UsersVM is defined as
public class UsersVm : ViewModelBase {}
and ViewModelBase is defined as
[Serializable] public class ViewModelBase {}
This gives me the following error:
The type "UsersVM" is not marked as serializable.
Why does this tell me this if I passed the userVm object to ViewModelBase (which is marked as Serializable) by passing it to Serialize(ViewModelBase instance) ?
I would think that passing UsersVM would be replaced by the base type ViewModelBase when passing it to a method that accepts ViewModelBase .
How can I serialize ViewModelBase?
source share