I'm trying to serialize my object using BinaryFormatter:
private UserSettings _userSettings;
var serializer = new BinaryFormatter();
using (var file = new FileStream(@"D:\test.bin", FileMode.Create))
{
serializer.Serialize(file, _userSettings);
}
But I'm getting a strange exception:
Type 'MyCustomUserControl' in Assembly 'xxx' is not marked as serializable.
Class UserSettings doesn't have any reference to MyCustomUserControl but it's referenced by MyCustomUserControl.
The reference to the control can be hidden in an event. If your UserSettings class implements an event to which the control is subscribed, add the [field:NonSerialized] attribute to the event:
[field:NonSerialized]
public event PropertyChangedEventHandler PropertyChanged;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With