Unable to edit the display order for multiple product specification attributes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello,
I'm encountering an error when trying to edit more than a dozen product specification attributes for a product. All is well for the first 10 or 11 attributes that I edit but once I reach anymore than that I receive an "error happened" and the update fails. I was able to narrow it down to the _CreateOrUpdate.SpecificationAttributes.cshtml file (calls the update function) and the ProductSpecAttrUpdate function in the Nop.Web/Administration/Controllers/ProductController.cs file. I don't know if this has happened to anyone else or if there is already a solution for it but I would like to know how I can fix this issue. Thanks for your help!

Btw, my nopCommerce version is 3.9.
4 years ago
Hello,

Unfortunately, unless we have the error details we cannot really help you. Could you follow this article and share the error details with us so we can try and figure out what issue are you having.

Regards,
Anton
4 years ago
Thanks for your reply, Anton.

The FullMessage details in the system log are as follows:

System.NullReferenceException: Object reference not set to an instance of an object.    
at Nop.Admin.Controllers.ProductController.<ProductSpecAttrList>b__100_0(ProductSpecificationAttribute x)    
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()    
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)    
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)    
at Nop.Admin.Controllers.ProductController.ProductSpecAttrList(DataSourceRequest command, Int32 productId)    
at lambda_method(Closure , ControllerBase , Object[] )    
at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)    
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)    
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)    
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)    
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)    
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)    
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()    
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
4 years ago
Anton,

If there is anything else that I can provide just let me know. I'd really like to see this fixed.
4 years ago
Re: "Object reference not set to an instance of an object"
This message thrown when you try to perform an action on a object which is not initialized. It's a very common error message. Try to debug if you have source code.
4 years ago
Thanks. I'll give it a try and see what I find out.
4 years ago
Hi, I apologize for the late reply.

I ended up adding a null condition to a couple of variables in the ProductSpecAttrList method. The reason is because it seems that specification attributes aren't always saved properly for products, at least that's what I've experienced so far. I know this isn't the best way to get around the problem but it's what I have at the moment. For example, the assignment block to the psaModel variable looks like the following now:

var psaModel = new ProductSpecificationAttributeModel
                    {
                        Id = x.Id,
                        AttributeTypeId = x.AttributeTypeId,
                        AttributeTypeName = x.AttributeType.GetLocalizedEnum(_localizationService, _workContext),

                        AttributeId = (x.SpecificationAttributeOption.SpecificationAttribute != null) ? x.SpecificationAttributeOption.SpecificationAttribute.Id : 0,
                        AttributeName = (x.SpecificationAttributeOption.SpecificationAttribute != null) ? x.SpecificationAttributeOption.SpecificationAttribute.Name : String.Empty,
                        AllowFiltering = x.AllowFiltering,
                        ShowOnProductPage = x.ShowOnProductPage,
                        DisplayOrder = x.DisplayOrder
                    };

As you can see I modified the AttributeId and AttributeName lines to default to 0 and an empty string if the SpecificationAttribute variable is null.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.