DeepCloner icon indicating copy to clipboard operation
DeepCloner copied to clipboard

Memory corruption and program crash when cloning TaskCancelledException

Open ian-g-holm-intel opened this issue 2 years ago • 0 comments

I've run into a problem where using DeepClone to clone a TaskCancelledException is corrupting memory and leading to a crash of my application. The exception is being thrown by Task.Delay(int, CancellationToken) when the token is cancelled. I believe the source of the problem is when it goes to clone the TaskCancelledException.Task property. This particular task includes a System.Threading.TimerQueueTimer object that I believe has native resources stored in it.

Is it possible to have some way to skip or configure how certain properties are cloned? For example, you could have attributes such as [IgnoreClone] or [ShallowClone] to specify that a property should default to being shallow cloned instead of attempting to deep clone. This way I could mark my Exception property as [ShallowClone] and it wouldn't even attempt to clone something that might have unmanaged resources in it.

ian-g-holm-intel avatar Nov 03 '22 19:11 ian-g-holm-intel