Developer forum

Forum » Swift » My favorites page bugged?

My favorites page bugged?

Fredrik
Fredrik
Reply

Hello

I get random null ref exception when accessing the My favorites page.

It's just like the products are in the list/lists (3 pcs, "default", "wish list" and "christmas wishes") but when I try to access them, it throw a null ref. Even weirder is when it gets a null ref when I check if it's null or not. (see picture) One time it passed and even .Count is displayed correctly, but further down in the code when it runs a .Take(2) from the list, it becomes a null ref there too - even though that function should not be able to give a null ref. When I insert a breakpint directly under foreach, you can see, for example, that there are 3 lists, but the list's product list cannot be displayed because "not all threads are running". Then I click on the icon to run the thread and then a null ref is displayed instead.

Best regards,

Fredrik

null_ref.png

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Can you provide the entire stack trace?

It seems like an exception coming from the viewengine when creating the theList.ProductList (ProductListViewmodel) - that property is lazy, so it will not execute untill you call it in the template - and from your screendump it seems like the ViewEngine is causing the issue.

It could be a missing currency or similar.

Which dw version is it?

 
Fredrik
Fredrik
Reply
DW version  9.12.0.0.

Error executing template "Designs/Swift/eCom/CustomerExperienceCenter/Favorites/FavoriteLists.cshtml"
System.NullReferenceException: Objektreferensen har inte angetts till en instans av ett objekt.
   vid Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetFavoriteListProducts(FavoriteListViewModelSettings settings, FavoriteList favoriteList)
   vid System.Lazy`1.CreateValue()
   vid System.Lazy`1.LazyInitValue()
   vid Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.<>c__DisplayClass31_0.<CreateView>b__0()
   vid System.Lazy`1.CreateValue()
   vid System.Lazy`1.LazyInitValue()
   vid CompiledRazorTemplates.Dynamic.RazorEngine_b29e31e6024e47fba3a19ee5f9363066.<RenderContent>b__0_0(TextWriter __razor_helper_writer) i \Files\Templates\Designs\Swift\eCom\CustomerExperienceCenter\Favorites\FavoriteLists.cshtml:rad 71
   vid CompiledRazorTemplates.Dynamic.RazorEngine_b29e31e6024e47fba3a19ee5f9363066.Execute() i \Files\Templates\Designs\Swift\eCom\CustomerExperienceCenter\Favorites\FavoriteLists.cshtml:rad 22
   vid RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   vid RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   vid RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   vid RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   vid Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   vid Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   vid Dynamicweb.Rendering.Template.RenderRazorTemplate()
 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Could it be that you have products on that list in a language that does not exist? Or a variant that does not exist?

You have a list ID for the given list - if you query [EcomCustomerFavoriteProducts] table for record that belong to the listid (Column [FavoriteListID]).

Could be a data mismatch in that table.

Also I can see we have changed how this is loaded in later versions (9.13+) - but if you have a product on the favoritelist (productid + variantid + the current language) I see that we can get into this exception.

 
Fredrik
Fredrik
Reply

I thought of a kind of data mismatch too, so I logged in via BO to check the lists and there was some products in the lists that is no longer exists the product catalog. I emptied the lists but the exception is still thrown.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I think you still have something there - probably related to missing language of a given product compared tot he language you are in the frontend?

It can also be that you have added a product that is not in assortment if that is enabled - that will also cause the below code to become null.

This is the code that causes the exception - I just added the null check for the product object marked as orange. My guess is that the green line returns a null - and that causes the next line to fail. It will return null if one of the IDs does not match a record in products or if the product is not in assortment...

foreach (var favoriteProduct in favoriteProducts)
            {
                var product = Services.Products.GetProductById(favoriteProduct.ProductId, favoriteProduct.ProductVariantId, settings.LanguageId);
                if (product is object && product.IsActive || !activeOnly)
                {
                    products.Add(product);
                }
            }

If you provide a solution URL we can have a look.

The fix will probably be the above which requires an upgrade to 9.14 or 9.15.

BR Nicolai

 
Merethe Vrå Andersen Dynamicweb Employee
Merethe Vrå Andersen
Reply

Hi, 

I have created bug #12749.

BR,

Merethe, QA

 

You must be logged in to post in the forum