SerializationException

Apr 23, 2012 at 6:45 PM

I have a view model where I'm attempting to use the Model and Expose attributes.  I've been trying to model my code after the PersonApplication example.

I declare a Catel property for the view model that will hold my model object.  I am passing the model object that I wish to edit into the view model constructor.  In the VM constructor, I am trying to set the property value, but when I do that I get the following exception:

SerializationException was unhandled by user code.  The constructor to deserialize an object of type MedicalLogModel.Patient ws not found.

I have decorated all of my model classes with the Serializable attribute.  The object in question for the error is a related object to the one I am trying to edit.  I am trying to edit a Prescription object which has a Patient property which is a reference to a Patient object.

What am I missing?

Coordinator
Apr 23, 2012 at 7:48 PM

The problem is that in WPF, binary serialization is used. In such case, you need a constructor like this:

/// <summary>
/// Initializes a new object based on <see cref="SerializationInfo"/>.
/// </summary>
/// <param name="info"><see cref="SerializationInfo"/>
//     that contains the information.</param>
/// <param name="context"><see cref="StreamingContext"/>.</param>
protected Patient(SerializationInfo info, StreamingContext context)
   : base(info, context) { }
The (de)serialization is used to make sure SaveViewModel and CancelViewModel are able to rollback changes on your model. If you don't need this, you can disable it by passing false to the first parameter of the view model base constructor.

Apr 23, 2012 at 9:24 PM

That took care of it.  Thanks!