Attempted to divide by zero.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hello,

I recently upgraded from v1.9 to v2.2. I get this error when trying to see the products under a Manufacturer and products under a Category:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Attempted to divide by zero.
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.DivideByZeroException: Attempted to divide by zero.

Source Error:


Line 59:         {
Line 60:             TotalCount = source.Count();
Line 61:             TotalPages = TotalCount / pageSize;
Line 62:
Line 63:             if (TotalCount % pageSize > 0)


Source File: C:\Users\Tesh\Downloads\nopCommerce_2.20_Source\Libraries\Nop.Core\PagedList.cs    Line: 61

Stack Trace:


[DivideByZeroException: Attempted to divide by zero.]
   Nop.Core.PagedList`1..ctor(IEnumerable`1 source, Int32 pageIndex, Int32 pageSize, Int32 totalCount) in C:\Users\Tesh\Downloads\nopCommerce_2.20_Source\Libraries\Nop.Core\PagedList.cs:61
   Nop.Services.Catalog.ProductService.SearchProducts(Int32 categoryId, Int32 manufacturerId, Nullable`1 featuredProducts, Nullable`1 priceMin, Nullable`1 priceMax, Int32 productTagId, String keywords, Boolean searchDescriptions, Int32 languageId, IList`1 filteredSpecs, ProductSortingEnum orderBy, Int32 pageIndex, Int32 pageSize, Boolean showHidden) in C:\Users\Tesh\Downloads\nopCommerce_2.20_Source\Libraries\Nop.Services\Catalog\ProductService.cs:310
   Nop.Web.Controllers.CatalogController.Manufacturer(Int32 manufacturerId, CatalogPagingFilteringModel command) in C:\Users\Tesh\Downloads\nopCommerce_2.20_Source\Presentation\Nop.Web\Controllers\CatalogController.cs:941
   lambda_method(Closure , ControllerBase , Object[] ) +217
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +51
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +409
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +52
   System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +127
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +436
   System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +305
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
   System.Web.Mvc.Controller.ExecuteCore() +136
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +232
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +68
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +61
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +31
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +56
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +110
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +690
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +194




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237


Can someone please help me?

Thanx
Tesh
12 years ago
I presume that your manufacturer page size (under 'SEO' tab) is set to 0. Set it to something positive
12 years ago
a.m. wrote:
I presume that your manufacturer page size (under 'SEO' tab) is set to 0. Set it to something positive


Thanx Andrei, that worked. That was a silly mistake by me
12 years ago
Got it! Thank you.

I even looked at the post you referenced, but looked at the main SEO page, not the category one.

Thanks again!
11 years ago
Hello.  We are facing this same issue.  The log shows the following URLs as to where they are coming from:

Page URL:   https://localhost/admin/product/relatedproductaddpopuplist?products-grid-size=25&productid=95&btnid=btnrefreshrelatedproducts&formid=product-form

The referrer URL.Referrer URL:   https://localhost/Admin/Product/RelatedProductAddPopup?productId=95&btnId=btnRefreshRelatedProducts&formId=product-form

Problem is I cannot seem to replicate it and the error happens a lot in our logs.  So I added the following the code to the PageList.cs file within Nop.Core.
// a page size should never come in being 0.  that'd cause an exception below when dividing by 0.
if (pageSize == 0) pageSize = 1;

I added this to each of the different methods.

I don't see us or the client changing the products-grid-size parameter at all, nor can you call the URL directly, so it's not like it is a build and open thing (when no default page is selected within VS).

Anyways, this hopefully will solve it, and for others.  Let me know if there is something else that it could be, so I can fix it.  (the setting you talked about above was set correctly.)
10 years ago
nop version 3.0

facing the same issue "divide by zero" i've done quiet the same as you @colinwiseman
if (pageSize == 0) pageSize = 1


i didn't saw any change in 3.10 how this issue.
6 years ago
a.m. wrote:
I presume that your manufacturer page size (under 'SEO' tab) is set to 0. Set it to something positive


Andrei - Is it not possible to prevent 0 paged size here?  Its very frustrating trying to solve this issue when a simple validation check to be greater than 0.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.