PropertyChangedEventManager is not marked as serializable

If you ever get the error “PropertyChangedEventManager is not marked as serializable.” This is probably because you are implementing INotifiyPropertyChanged incorrectly.

The solution is to mark your PropertyChangedEventManager as NonSerialized.

#region INotifyPropertyChanged Members

[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;


protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, e);
}
}

#endregion

3 comments:

  1. Thanks, this fixed the problem I had. (Including one I didn't even attribute to this scenario.)

    ReplyDelete
  2. Thanks man. It was obvious when I read it, but I was going to take a lot longer to get there!

    ReplyDelete