private static void WriteSerializedData(IRecord record) { byte[] buffer; using (var s = new MemoryStream()) using (var sw = new StreamWriter(s)) { var serializer = new Serialization.MySerializer(sw); serializer.Serialize(record); sw.Flush(); var len = s.Length; s.Seek(0, SeekOrigin.Begin); buffer = new byte[len]; s.Read(buffer, 0, (int)len); } var serialized = Encoding.UTF8.GetString(buffer); Console.WriteLine(serialized); }