Closed isaaclyman closed 2 years ago
I've finally nailed down the issue. Commenting here for posterity.
DeepCloning an IEnumerable, especially if that IEnumerable is lazily-evaluated from database query or other async action, is a volatile combination. Throw in a couple of async boundaries and some heavy reflection and you get a disaster.
Solution: avoid DeepCloning something with an IEnumerable in it. Coerce the IEnumerable to an array first.
DeepClone is able to cause anonymous/untraceable errors in system code. I'm a few hours in now debugging an unpredictable exception. It has no stacktrace that would lead to my own code or to DeepClone.
The error has reported out as:
By stepping through my code, I've finally narrowed the issue down to a usage of
ActionExecutedContext.Result.DeepClone()
. I'm sure it's my fault, I'm probably cloning something I shouldn't be (something that has a reference to itself or a pointer to an object held by some other process or a system object...I've been reading the other issues on this repo so I understand there are some things that shouldn't ever be cloned).I'm okay with the cloning restrictions and I'll figure out what's going on, but it would have saved me some time if DeepCloner had some error handling built in. try/catch stuff. It wouldn't need to tell me exactly what the problem is, it would just be nice to know that the error is happening in DeepCloner and not somewhere else, since you can see that isn't clear at all from the errors I'm getting.
Is that a possibility for a future version?
EDIT: On further investigation, it's not at all certain that the error is happening during the DeepClone so this might be a red herring. Sorry for the trouble.