private static void TextEncodingRoundrip(Encoding encoding)
        {
            using var stream = new MemoryStream();

            using (var writer = new ObjectWriter(stream, leaveOpen: true))
            {
                SerializerService.WriteTo(encoding, writer, CancellationToken.None);
            }

            stream.Position = 0;

            using var reader = ObjectReader.TryGetReader(stream);
            Assert.NotNull(reader);
            var actualEncoding   = (Encoding)SerializerService.ReadEncodingFrom(reader, CancellationToken.None).Clone();
            var expectedEncoding = (Encoding)encoding.Clone();

            // set the fallbacks to the same instance so that equality comparison does not take them into account:
            actualEncoding.EncoderFallback   = EncoderFallback.ExceptionFallback;
            actualEncoding.DecoderFallback   = DecoderFallback.ExceptionFallback;
            expectedEncoding.EncoderFallback = EncoderFallback.ExceptionFallback;
            expectedEncoding.DecoderFallback = DecoderFallback.ExceptionFallback;

            Assert.Equal(expectedEncoding.GetPreamble(), actualEncoding.GetPreamble());
            Assert.Equal(expectedEncoding.CodePage, actualEncoding.CodePage);
            Assert.Equal(expectedEncoding.WebName, actualEncoding.WebName);
            Assert.Equal(expectedEncoding, actualEncoding);
        }