-
Notifications
You must be signed in to change notification settings - Fork 100
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 in InternalCopy #9
Comments
It's recursion, it should work. Can you provide simple code describing class that result in your error? |
I deal with the same issue, leading to the StackOverflow exception when creating a copy of a large object, when I debugged I found the following details regarding the issue: Method - private static Object InternalCopy(Object originalObject, IDictionary<Object, Object> visited) Other details that you might be keen about are:
I am not sure if I have a simple way to provide you the details of the issue, as it is part of our project. Let me known in case you want me to try few options to provide debug details Also does this need implementation of the extension methods for the child objects too, I am assuming No |
I have some new ideas about what might be the cause, I'll check them. |
Thanks Alex. Please let me know when you have an update, I can test the changes. |
Hi there! My very first attempt to copy a complex business object resulted in a stack overflow exception, too. I've nailed it down to a regular expression somewhere deep down in my object hierarchy. It's simple enough to reproduce, but unfortunately I have no idea how to fix it. Regex re = new Regex(@"\w", RegexOptions.Compiled);
Regex re2 = re.Copy<Regex>(); // <--- StackOverflow exception HTH and best regards, |
Thank you, will check it out. |
Checked it, yes I can reproduce this. I know why it happen, and will fix it soon. But
2.I will fix this problem. The problem is in System.Reflection.Pointer object that holds Void* pointer, when I'm getting its value, it returns new Object (different object Reference) but it points to same memory address. So we have endless cycle because, the field value always return new Object instance, note that its not recursion (I store visited nodes), its endless stream of objects. |
I was able to solve the problem with unmanaged pointers, but your object with Regex still will not work, the problem is in System.Reflection.Emit.SignatureHelper class that is used inside Regex, it's GetHashCode() is poorly implemented and throw NullReferenceException
notice the usage of m_module, it's null in your example. |
I'm not sure I want to commit the unmanaged pointers fix. Though it will fix some problems, but this is far beyond this code usage. If I will start dealing with unmanaged memory, its not gonna end well.
|
Hi Burtsev, Thanks and Regards, |
In InternalCopy, there is a line:
CopyFields(originalObject, visited, cloneObject, typeToReflect);
...but then in CopyFields, you have the line:
var clonedFieldValue = InternalCopy(originalFieldValue, visited);
This results in a StackOverflow exception.
The text was updated successfully, but these errors were encountered: