Modernized version of the extension methods for ToStream:
public static Stream ToStream(this string value) => ToStream(value, Encoding.UTF8); public static Stream ToStream(this string value, Encoding encoding) => new MemoryStream(encoding.GetBytes(value ?? string.Empty)); It was suggested in a comment of @JoelNet's answer and @Shaun Bowe answer. Because I agree with @Palec's comment.