private static object DeserializeObject(byte[] value, Type valueType) { var readRootValueAsArray = IsArrayType(valueType); try { return(RoundTripBsonConvert.DeserializeObject(value, valueType, readRootValueAsArray: readRootValueAsArray)); } catch (JsonSerializationException ex) { throw new FormatException($"Failed to deserialize value to type {valueType.FullName}", ex); } }
private static byte[] SerializeObject(object value, Type valueType) { // Special handling for Task to make it more obvious when an await is missing. if (value is System.Threading.Tasks.Task) { throw new FormatException($"Failed to serialize value of type {valueType.FullName}"); } try { return(RoundTripBsonConvert.SerializeObject(value)); } catch (JsonWriterException ex) { throw new FormatException($"Failed to write value of type {valueType.FullName}", ex); } catch (JsonSerializationException ex) { throw new FormatException($"Failed to serialize value of type {valueType.FullName}", ex); } }