Table of Contents

Class ShapeShiftSerializationException

Namespace
ShapeShift
Assembly
ShapeShift.dll

The exception thrown when a value cannot be serialized or deserialized.

public class ShapeShiftSerializationException : Exception, ISerializable
Inheritance
ShapeShiftSerializationException
Implements
Inherited Members

Remarks

ShapeShift augments these exceptions with a Path breadcrumb trail as the failure propagates out through the converters that were responsible for each enclosing map property or vector element. The path is rendered into Message so that logs identify precisely which value failed, even when the failure originates deep inside a large object graph.

Exceptions thrown by user code (including custom converters) are never swallowed: they are preserved as the InnerException of the exception that carries the path.

Instances of this type are not thread-safe. A single (de)serialization operation is expected to augment the path on the thread that is unwinding the failure.

Constructors

ShapeShiftSerializationException(string)

Initializes a new instance of the ShapeShiftSerializationException class.

public ShapeShiftSerializationException(string message)

Parameters

message string

The message that describes the failure.

ShapeShiftSerializationException(string, Exception?)

Initializes a new instance of the ShapeShiftSerializationException class.

public ShapeShiftSerializationException(string message, Exception? innerException)

Parameters

message string

The message that describes the failure.

innerException Exception

The exception that caused this failure, if any.

ShapeShiftSerializationException(string, Exception?, ShapeShiftPath)

Initializes a new instance of the ShapeShiftSerializationException class with an initial Path.

public ShapeShiftSerializationException(string message, Exception? innerException, ShapeShiftPath path)

Parameters

message string

The message that describes the failure.

innerException Exception

The exception that caused this failure, if any.

path ShapeShiftPath

The location of the value that failed, relative to the root of the document being processed.

Properties

Message

Gets the message that describes the failure, including the Path when one is known.

public override string Message { get; }

Property Value

string

Path

Gets the location of the value that failed to (de)serialize, relative to the root of the document.

public ShapeShiftPath Path { get; }

Property Value

ShapeShiftPath

Root when the failure was not attributable to a particular value within a map or vector.

Methods

AddEnclosingPathElement(ShapeShiftPathElement)

Records that this failure occurred within the value identified by element of an enclosing map or vector, prepending it to Path.

public bool AddEnclosingPathElement(ShapeShiftPathElement element)

Parameters

element ShapeShiftPathElement

The step from the enclosing container to the value that was being processed.

Returns

bool

Always true, so that this method may be invoked from an exception filter that rethrows.

Examples

try
{
    this.elementConverter.Write(ref encoder, element, context);
}
catch (ShapeShiftSerializationException ex) when (ex.AddEnclosingPathElement(index))
{
    throw;
}

Remarks

Converters call this method as an exception propagates outward so that the outermost frame observes a complete path from the root of the document.