As promised in the previous post “How to implement a generic Shallow-Clone for an object in C#” this will demonstrate deep-cloning objects that don’t explicitly support the behavior. Before I continue I will again state that I don’t recommend this approach. It will be many times slower than a properly implemented Clone() and can cause [...]


This implementation makes heavy use of the FormatterServices object used by serialization: It provides several helpful methods in this case that are aware of custom serialization options like [NonSerialized]. In the case of an object not being marked [Serializable] you have to create field list manually. Here is an example shallow object clone: using [...]


How to throw the InnerException of a TargetInvocationException without loosing stack details? I’ve been plagued by this problem for some time. There are a few common solutions to this: Option #1 – just leave it alone. The downfall here is that specific types of exceptions cannot be caught easily in calling code. In some instances [...]