You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6.0 Swagger多文件上传报错:index0errorValue must be a string

问题:Swagger将IFormFile集合解析为字符串列表引发报错

我定义了一个接收表单文件集合的接口:

[HttpPost]
[Route("test_file")]
public async Task<IActionResult> test_file([FromForm] IEnumerable<IFormFile> lstFile)
{
    return null;
}

但Swagger错误地将该参数解析为字符串列表,调用接口时出现报错:"index0errorValue must be a string"


解决方法

通过关闭Swagger配置中的SerializeAsV2选项,问题得以解决。修改后的Swagger配置代码如下:

app.UseSwagger(options =>
{
//options.SerializeAsV2 = true;
options.RouteTemplate = swaggerOption.JsonRoute;
});

目前暂未明确该问题的具体原理,但关闭SerializeAsV2后,Swagger对IFormFile集合的解析恢复正常,报错不再出现。


内容的提问来源于stack exchange,提问作者tThangG

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 01:32:04