diff --git a/libraries/Microsoft.Bot.Schema/Attachment.cs b/libraries/Microsoft.Bot.Schema/Attachment.cs
index a4291ba006..b89d102cfa 100644
--- a/libraries/Microsoft.Bot.Schema/Attachment.cs
+++ b/libraries/Microsoft.Bot.Schema/Attachment.cs
@@ -3,6 +3,7 @@
namespace Microsoft.Bot.Schema
{
+ using Microsoft.Bot.Schema.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -53,6 +54,7 @@ public Attachment(string contentType = default, string contentUrl = default, obj
///
/// The embedded content.
[JsonProperty(PropertyName = "content")]
+ [JsonConverter(typeof(AttachmentMemoryStreamConverter))]
public object Content { get; set; }
///
diff --git a/libraries/Microsoft.Bot.Schema/Converters/AttachmentMemoryStreamConverter.cs b/libraries/Microsoft.Bot.Schema/Converters/AttachmentMemoryStreamConverter.cs
new file mode 100644
index 0000000000..8667bd215f
--- /dev/null
+++ b/libraries/Microsoft.Bot.Schema/Converters/AttachmentMemoryStreamConverter.cs
@@ -0,0 +1,196 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Newtonsoft.Json.Serialization;
+
+namespace Microsoft.Bot.Schema.Converters
+{
+ ///
+ /// Converter which allows a MemoryStream instance to be used during JSON serialization/deserialization.
+ ///
+#pragma warning disable CA1812 // Avoid uninstantiated internal classes.
+ internal class AttachmentMemoryStreamConverter : JsonConverter
+ {
+ public override bool CanConvert(Type objectType)
+ {
+ return typeof(MemoryStream).IsAssignableFrom(objectType);
+ }
+
+ ///
+ /// If the object is of type:
+ ///
+ /// -
+ /// List/Array
+ ///
+ /// - Without MemoryStream: it will return a JArray.
+ /// - With MemoryStream: it will return a List.
+ ///
+ ///
+ /// -
+ /// Dictionary/Object
+ ///
+ /// - Without MemoryStream: it will return a JObject.
+ /// - With MemoryStream: it will return a Dictionary.
+ ///
+ ///
+ ///
+ ///
+ ///
+ public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+ {
+ if (reader.TokenType == JsonToken.Null)
+ {
+ return JValue.CreateNull();
+ }
+
+ if (reader.TokenType == JsonToken.StartArray)
+ {
+ var list = new List