Out of memory error on image uploading

Server Error in '/' Application.


Out of memory.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.OutOfMemoryException: Out of memory.

Source Error: 
 

Line 885:        {
Line 886:            Image img;
Line 887:            img = Image.FromFile(sourceImageUrl);
Line 888:            if (img.Height < maxHeight && img.Width < maxWidth) return img;
Line 889:            using (img)


Source File: F:\aj\pi\Development\abex\Ecomm\SC\YooslayShopingCart\YooSlayShoppingCartV5\ShoppingCart.Common\BusinessManager.cs    Line: 887 

Stack Trace: 
 

[OutOfMemoryException: Out of memory.]
   System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement) +478509
   System.Drawing.Image.FromFile(String filename) +11
   ShoppingCart.Common.BusinessManager.ResizeImage(String sourceImageUrl, Int32 maxWidth, Int32 maxHeight) in F:\aj\pi\Development\abex\Ecomm\SC\YooslayShopingCart\YooSlayShoppingCartV5\ShoppingCart.Common\BusinessManager.cs:887
   ShoppingCart.WebUI.Areas.Dashboard.Controllers.ProductController.CreateProduct(ProductViewModel dto, String savecontinue) in F:\aj\pi\Development\abex\Ecomm\SC\YooslayShopingCart\YooSlayShoppingCartV5\ShoppingCart.WebUI\Areas\Dashboard\Controllers\ProductController.cs:275
   lambda_method(Closure , ControllerBase , Object[] ) +146
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +157
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d() +50
   System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +228
   System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +228
   System.Web.Mvc.Async.<>c__DisplayClass33.b__32(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +26
   System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
   System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) +12
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9874329
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +48
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +159

 


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3056.0

By      21-Nov-2023    2

Solutions


Adil Shahbaz

Please Update Web Config. 

Add this line in web config > system.web

<httpRuntime targetFramework="4.5" maxRequestLength="102400" requestLengthDiskThreshold="61920" />
 

Your Answer

10123