Developer forum

Forum » Development » NullReferenceException ProductsAndGroupsHandler.AddHandlerToCache

NullReferenceException ProductsAndGroupsHandler.AddHandlerToCache

Unnsteinn Garðarsson
Unnsteinn Garðarsson
Reply

We are encountering some instances of the below error, looks like some missing null checks on your behalf in the AddHandlerToCache method
 

Origin: LogEventBeforeSave - Action: Parsing - Category: Application - ExceptionType: NullReferenceException - Description: Processed data: [some][g:GROUP582]; Default type: All. - StackTrace: 2021-04-06 20:50:25.432: Processed data: [some][g:GROUP582]; Default type: All.. System.NullReferenceException: Object reference not set to an instance of an object.   
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)   
   at Dynamicweb.Ecommerce.Extensibility.Controls.ProductsAndGroupsHandler.AddHandlerToCache(ProductsAndGroupsHandler handler, String handlerData)   
   at Dynamicweb.Ecommerce.Extensibility.Controls.ProductsAndGroupsHandler.ParseData(String data, Boolean loadDataFromDatabase, HandlerConfigurationType defaultDataType, List`1& productIdAndVariantIds, List`1& groupIds, HashSet`1& iQueries)

Regards.


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

What version...?

The current code base contains this:

private static void AddHandlerToCache(ProductsAndGroupsHandler handler, string handlerData)
        {
            string key = string.Format("{0}_{1}", Common.Context.LanguageID, handlerData);
            if (CachedHandlers is null || CachedHandlers.ContainsKey(key))
            {
                return;
            }

            CachedHandlers.Add(key, handler);
        }

So it should not happen (unless there is a threading issue...!)

 

You must be logged in to post in the forum