version 4.0 - error on payment restrictions configuration

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

I am new to nopCommerce. I downloaded and installed version 4.0 nopCommerce. While in configuration, under payment restrictions, I attempted to restrict all payment methods in all countries except US. When I clicked save, the system crashed and gave me the below error exception in 2017 Visual Studio Community.

The error occurred in the ApplicationBuilderExtensions.cs

Line: 81

The error message:  System.IO.InvalidDataException: 'Form value count limit 1024 exceeded.'

System.IO.InvalidDataException occurred
  HResult=0x80131501
  Message=Form value count limit 1024 exceeded.
  Source=Nop.Web.Framework
  StackTrace:
   at Nop.Web.Framework.Infrastructure.Extensions.ApplicationBuilderExtensions.<>c.<UseNopExceptionHandler>b__1_1(HttpContext context) in C:\Users\jimth_000\Source\repos\NopCommerce\Presentation\Nop.Web.Framework\Infrastructure\Extensions\ApplicationBuilderExtensions.cs:line 81
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()


I tried checking off one column at a time. The error occurs after 4 columns are saved. Even after restarting the application this occurs. I have also uninstalled and reinstalled the application several times and this error still occurs.

Can anyone please provide some guidance on why this happens and how to prevent this?

Thank you in advance.
Jim Thomas
6 years ago
Hi Jim,

We'll investigate it in the near time - https://github.com/nopSolutions/nopCommerce/issues/2743
6 years ago
Getting this error on Version 4.0 when configuring payment restrictions for Braintree plugin to multiple countries.  Can do a few at a time.

Thx.
6 years ago
Actually, hit a limit and couldn't even do one a time, with 5 installed payment plugins showing.  
(see here: https://www.nopcommerce.com/boards/t/50577/payment-restrictions-invaliddataexception-form-value-count-limit-1024-exceeded-payment.aspx

Uninstalled one payment method and was able to continue.
5 years ago
Done. Please see this commit for more details
5 years ago
Resolved Below Error:
The error message:  System.IO.InvalidDataException: 'Form value count limit 1024 exceeded.'
Solution:

You have to create Filter Attribute. So create below Filter in Nop.Web.Framework.Mvc.Filters

-------------------------------------------------------------------------------------------
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Nop.Web.Framework.Mvc.Filters
{
    public class RequestFormSizeLimitAttribute : Attribute, IAuthorizationFilter,IOrderedFilter
    {
        private readonly FormOptions _formOptions;
        public RequestFormSizeLimitAttribute(int valueCountLimit)
        {
            _formOptions = new FormOptions()
            {
                ValueCountLimit = valueCountLimit
            };
        }
        public int Order { get; set; }
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var features = context.HttpContext.Features;
            var formFeature = features.Get<IFormFeature>();
            if (formFeature == null || formFeature.Form == null)
            {
                features.Set<IFormFeature>(new FormFeature(context.HttpContext.Request,
                _formOptions));
            }
        }
    }
}

After create filter, Add this filter on "MethodRestrictionsSave" Method Like Below.


        [AdminAntiForgery(true)]
       [RequestFormSizeLimit(valueCountLimit: 2048)]
        [HttpPost, ActionName("MethodRestrictions")]
        public virtual IActionResult MethodRestrictionsSave(IFormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
                return AccessDeniedView();
5 years ago
Hi,

It's possible that Shipping/Restrictions have the same problem.


Thanks
5 years ago
kava wrote:
Hi,

It's possible that Shipping/Restrictions have the same problem.


Thanks



Yes you're right, it's possible. We increase this count too. Please see this commit for more details. Thank you.
5 years ago
is there a way to risolve this bug for 4.0 ?
5 years ago
kava wrote:
is there a way to risolve this bug for 4.0 ?


Unfortunately the only way we could find for 4.0 is to change the global settings, as described here https://stackoverflow.com/a/50077801
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.