Handling Large JSON Payloads in ASP.NET Core 6.0 with OutOfMemoryException
I can't seem to get I'm dealing with After trying multiple solutions online, I still can't figure this out... I'm currently developing an ASP.NET Core 6.0 Web API that needs to handle large JSON payloads from client requests. My API endpoint is designed to accept a JSON object containing multiple records, sometimes exceeding 10 MB in size. However, when I try to post these large payloads, I encounter an `OutOfMemoryException`. Here's the code for my controller method: ```csharp [HttpPost] public async Task<IActionResult> UploadData([FromBody] List<MyDataModel> data) { // Process the incoming data foreach (var item in data) { // Simulate processing await Task.Delay(10); } return Ok(); } ``` I've tried increasing the request body size limit in my `Startup.cs` as follows: ```csharp services.Configure<KestrelServerOptions>(options => { options.Limits.MaxRequestBodySize = 10485760; // 10MB }); ``` Despite this, I'm still hitting the memory scenario. I also confirmed that the server has enough available memory when the request is made. I'm wondering if this is a limitation in the default JSON serialization settings or if there are any best practices for handling such large payloads effectively. I've considered switching to streaming the data, but I'm unsure how to implement that in this context. Any guidance on efficiently managing large JSON data in ASP.NET Core would be greatly appreciated! I'm working on a application that needs to handle this. Any advice would be much appreciated. I'm coming from a different tech stack and learning C#. Thanks for your help in advance! This is part of a larger mobile app I'm building. Is there a simpler solution I'm overlooking? I'm on Windows 10 using the latest version of C#. Has anyone dealt with something similar?