Example #1
0
        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);
            }
        }