【发布时间】:2021-06-04 07:06:44
【问题描述】:
我有一个模型用作 post 方法的参数。
我的模型是:
public class SendObject
{
public string Id { get; set; }
public string Body { get; set; }
public string Subject { get; set; }
public SendObjectParameters Parameters { get; set; }
public object[] Attachments { get; set; }
}
public class SendObjectParameters
{
public string Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Address { get; set; }
}
我有一个附件,我想用Attachments = new[] { attachment } 发送我的附件是一个excel 文件,附件类型是FileStreamResult。
在 post 方法中,我尝试像 string content = JsonConvert.SerializeObject(sendContent); 一样序列化这个对象。我得到一个关于序列化的错误:Newtonsoft.Json.JsonSerializationException: Error getting value from 'ReadTimeout' on 'System.IO.MemoryStream'. ---> System.InvalidOperationException: Timeouts are not supported on this stream.
我该如何解决这个问题?
【问题讨论】:
-
为什么要序列化为JSON?有多大?
标签: c# json asp.net-core type-conversion filestream