net-object-deep-copy
net-object-deep-copy copied to clipboard
StackOverflow when Copy() my Class which inherits from INotifyPropertyChanged
Hey there,
i've got a class with three custom Enum types, some bools and some strings. Systemwise i'm using the ms-class System.ServiceProcess.ServiceController and System.Windows.Controls.DatePicker. last but not least i implement the INotifyPropertyChanged Interface. public event PropertyChangedEventHandler PropertyChanged;
and:
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
The error is a stack overflow @ line 28: var cloneObject = CloneMethod.Invoke(originalObject, null); Error:
System.StackOverflowException was unhandled HResult=-2147023895 Message=Eine Ausnahme vom Typ "System.StackOverflowException" wurde ausgelöst. InnerException:
is this an issue or why does that not work?
This happens when you try to clone .NET Framework objects that has inner references to almost everything in .NET runtime. Basically you are cloning whole .NET Runtime, and run out of stack memory. This is not a bug in clone code.
You should clone objects whose structure is known to you, or you are sure that their object graph is less then 10 000 objects. I do not recommend cloning classes that you or your team havn't written themself, nor with this code nor with any other clone code, its just a bad practice.