PagedList.cs division by zero

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
in case it hasn't been fixed by now:

 src/Libraries/Nop.Core/PagedList.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Libraries/Nop.Core/PagedList.cs b/src/Libraries/Nop.Core/PagedList.cs
index 3e540e7..09a8053 100644
--- a/src/Libraries/Nop.Core/PagedList.cs
+++ b/src/Libraries/Nop.Core/PagedList.cs
@@ -60,7 +60,7 @@ namespace Nop.Core
         public PagedList(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount)
         {
             TotalCount = totalCount;
-            TotalPages = TotalCount / pageSize;
+            TotalPages = TotalCount / (pageSize < 1 ? 1 : pageSize);

             if (TotalCount % pageSize > 0)
                 TotalPages++;
8 years ago
0 is not allowed as "pageSize" parameter. We've already fixed it as adding appropriate validation )in the upcoming version 3.80):
if (pageSize <= 0)
   throw new ArgumentException("pageSize must be greater than zero");
3 years ago
Running 4.3 I am still getting this same error :
DivideByZeroException: Attempted to divide by zero.
Nop.Core.PagedList<T>..ctor(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount) in PagedList.cs, line 66
3 years ago
I don't see the above mentioned validation / throw in the 4.30 code.
In any case, you need to fix the underlying problem / page size....
In admin > All Settings, search for pagesize, and fix any that are 0.
3 years ago
hey - thanks for the response - I'm already at 4.3 ( mistakenly wrote 4.1 and didn't find a way to make an edit). The divide by zero also happens when that field is empty ( which it was by default for many items ) - fixed this, but I think all items should have a default setting of 0.

further to my css issues - I'm finding that as well as not updating and/or not minifying, that after new builds I get varying number of .css files in my bundle folder - sometimes 1 - 2 or even 3.  There is a lot of duplicated code in these files and I'm very suspicious as to this inconsistency in the number of files produced.

thanks again
b
3 years ago
Hello! How do I solve this problem, it gives me this same error in version 4.3

thanks!
3 years ago
Have you searched for underlying problem / page size....
In admin > All Settings, search for pagesize, and fix any that are 0.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.