Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflow when Copy() my Class which inherits from INotifyPropertyChanged #18

Open
wolfomat opened this issue May 18, 2016 · 2 comments

Comments

@wolfomat
Copy link

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:

@wolfomat
Copy link
Author

is this an issue or why does that not work?

@Burtsev-Alexey
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants