AspNetCoreOData
AspNetCoreOData copied to clipboard
Maximum number of bytes exceeded
Assemblies affected ASP.NET Core OData 8.0.8
Describe the bug Maximum number of bytes exceeded when calling an action.
Reproduce steps Call an action such as:
[HttpPost("/api/ImportItems()")]
public async Task<IActionResult> ImportItems([FromODataBody] byte[] data)
with a data size > 2MB
Expected behavior Being able to receive the data.
Additional context
Microsoft.OData.ODataException: The maximum number of bytes allowed to be read from the stream has been exceeded. After the last read operation, a total of 1114112 bytes has been read from the stream; however a maximum of 1048576 bytes is allowed.
at Microsoft.OData.MessageStreamWrapper.MessageStreamWrappingStream.IncreaseTotalBytesRead(Int32 bytesRead)
at Microsoft.OData.MessageStreamWrapper.MessageStreamWrappingStream.ReadAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
If I do
ODataMessageReaderSettings settings = this.HttpContext.Request.GetReaderSettings();
in another method in the same controller, I can see that settings.MessageQuotas.MaxReceivedMessageSize
is 9223372036854775807.
The maximum size mentioned in the exception seems to be:
/// <summary>The default maximum number of bytes that should be read from a message.</summary>
internal const long DefaultMaxReadMessageSize = 1024 * 1024;
Expected behavior Being able to receive the data.
Why do you think that's what the behavior should be though? Isn't the message clearly saying it crossed the limit? Feels like 100% intentional behavior to me.
I understand the potential confusion with that other property showing 9223372036854775807
, but it could just be a separate thing altogether, couldn't it?
Have you looked into using Stream
s instead of passing all the data in one go?
Expected behavior Being able to receive the data.
Why do you think that's what the behavior should be though? Isn't the message clearly saying it crossed the limit? Feels like 100% intentional behavior to me.
Since I haven't seen any documentation stating that there's a request size limit, I think it's a fare assumption that it would work.
I understand the potential confusion with that other property showing
9223372036854775807
, but it could just be a separate thing altogether, couldn't it?
I guess. Thats's kind of the question.
Have you looked into using
Stream
s instead of passing all the data in one go?
No, I have not.
I think this should be moved to discussions.
Thank you @Robelind for reporting the issue. Could you please share a repro to help us with identifying what is causing the limit violation?
@Robelind You could also try the suggestion here. The limit you're observing could be getting imposed by the framework https://stackoverflow.com/questions/3668155/how-do-i-resolve-the-maximum-request-length-exceeded-exception
@Robelind Do you need further help with this?
@gathogojr Yes, I do. I'd like to know how to increase the request size limit, to be able to received larger amounts of data.
@Robelind In this comment, I suggested that the limit you're observing could be getting imposed by the framework and asked you to try increase the limit as suggested on the StackOverflow post. Did you try that?