I'm getting this error when uploading a file that is 84MB (see error below) but when I upload a ~60MB file, it works fine. This only occurs on our 32bit 2008 VM w/ 4GB memory. On my R2 64bit VM w/8GB memory, it works fine with even 130MB file.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at System.IO.BinaryReader.ReadBytes(Int32 count) at CustWeb.Controllers.DownloadsController.Create(Download dl, HttpPostedFileBase file) in c:\...\CustWeb\Controllers\DownloadsController.cs:line 72
I monitored the Memory in the task manager, though, and it never goes above 74% during the entire upload process.
This is an MVC 4 application on the 4.5 .NET framework.
I have the max settings in my web.config in dealing with uploading files.
<httpRuntime requestValidationMode="4.5" targetFramework="4.5" maxRequestLength="2147483647" executionTimeout="84000" />
...
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147482624" />
</requestFiltering>
</security>
UPDATE Adding code as requested:
public ActionResult Create(Download dl, HttpPostedFileBase file)
{
try
{
using (var binaryReader = new BinaryReader(file.InputStream))
{
dl.FileBytes = binaryReader.ReadBytes(file.ContentLength);
}
dl.FileContentType = file.ContentType;
dl.FileName = file.FileName;
dl.Insert();
Success("<strong>" + dl.Label + "</strong> created and uploaded successfully.");
return RedirectToAction("Index");
}
catch (Exception ex)
{
SelectList list = new SelectList(new DownloadType().GetDownloadTypes(), "ID", "Name");
ViewBag.DownloadTypeList = list;
Error(ex.ToString());
return View(dl);
}
}
BinaryReaderhere is wrong.