-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Closed
dotnet/corefx
#40792Description
When returning a single JSON string of about 3,5 MB from a controller's action (return type byte[]), the mentioned System.ArgumentException exception is thrown in my asp.net Core 3.0 (Preview 8) Api project.
Looking through the docs, there seems to be no option to adjust any limit regarding this issue.
[HttpPost]
public async Task<ActionResult<byte[]>> GetFile()
{
var largeArray = new byte[3.5 * 1024 * 1024];
return largeArray;
}Exception:
System.ArgumentException
HResult=0x80070057
Message=The JSON value of length 3770846 is too large and not supported.
Source=System.Text.Json
StackTrace:
at System.Text.Json.ThrowHelper.ThrowArgumentException_ValueTooLarge(Int32 tokenLength)
Call stack:
System.Text.Json.dll!System.Text.Json.ThrowHelper.ThrowArgumentException_ValueTooLarge(int tokenLength)
System.Text.Json.dll!System.Text.Json.Utf8JsonWriter.WriteBase64StringValue(System.ReadOnlySpan<byte> bytes)
System.Text.Json.dll!System.Text.Json.Serialization.Converters.JsonConverterByteArray.Write(System.Text.Json.Utf8JsonWriter writer, byte[] value, System.Text.Json.JsonSerializerOptions options)
System.Text.Json.dll!System.Text.Json.JsonPropertyInfoNotNullable<object, byte[], byte[], byte[]>.OnWrite(ref System.Text.Json.WriteStackFrame current, System.Text.Json.Utf8JsonWriter writer)
System.Text.Json.dll!System.Text.Json.JsonPropertyInfo.Write(ref System.Text.Json.WriteStack state, System.Text.Json.Utf8JsonWriter writer)
System.Text.Json.dll!System.Text.Json.JsonSerializer.Write(System.Text.Json.Utf8JsonWriter writer, int originalWriterDepth, int flushThreshold, System.Text.Json.JsonSerializerOptions options, ref System.Text.Json.WriteStack state)
System.Text.Json.dll!System.Text.Json.JsonSerializer.WriteAsyncCore(System.IO.Stream utf8Json, object value, System.Type type, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken)
System.Text.Json.dll!System.Text.Json.JsonSerializer.SerializeAsync(System.IO.Stream utf8Json, object value, System.Type type, System.Text.Json.JsonSerializerOptions options, System.Threading.CancellationToken cancellationToken)
Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Formatters.SystemTextJsonOutputFormatter.WriteResponseBodyAsync(Microsoft.AspNetCore.Mvc.Formatters.OutputFormatterWriteContext context, System.Text.Encoding selectedEncoding)
Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Formatters.TextOutputFormatter.WriteAsync(Microsoft.AspNetCore.Mvc.Formatters.OutputFormatterWriteContext context)
There seems to be a fixed max length constant JsonConstants.MaxBase46ValueTokenSize (btw, typo in the constant's name) set to 125 KB, that JsonWriterHelper.ValidateBytes() checks against.
Of course I can change the response type to plain\text and return it as such. Is that the intention of the hard coded 125 KB limit, or what's the reason for that?
Reactions are currently unavailable