Skip to content

NullReferenceException in GetGroupAssets when calling node.GetProductGroup() on freshly created menu items #555

@ruwandkp

Description

@ruwandkp

When creating a new menu item in the content tree, the frontend crashes with a NullReferenceException when the navigation template attempts to fetch the associated product group using node.GetProductGroup().

The error originates deep within Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetGroupAssets. It appears that for newly created nodes, the core engine attempts to process group assets before they are fully cached or initialized, failing to handle null values gracefully and causing a fatal crash instead of returning an empty model or null.

Steps to Reproduce:

  1. Use a Dynamicweb 10 environment with Swift.
  2. Create a brand new menu item in the backend.
  3. Load the frontend page where the menu is rendered.
  4. The page will crash with a NullReferenceException.

Stack Trace:

Error executing template "Designs/Swift-v2/Paragraph/Swift-v2_MenuRelatedContent/Menu.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.GetGroupAssets(MediaViewModelSettings settings, Group group)
at Dynamicweb.Ecommerce.ProductCatalog.ViewEngine.CreateProductGroup(ProductGroupViewModelSettings settings, ViewModelPropertyFiller1 filler, Group group) at Dynamicweb.Ecommerce.ProductCatalog.NavigationTreeViewNodeExtensions.GetProductGroup(NavigationTreeNodeViewModel node) at CompiledRazorTemplates.Dynamic.RazorEngine_0e5740b69a1c4d42979790ac728b7ca8.GetGroupFieldValue(String fieldSystemName, NavigationTreeNodeViewModel node) at CompiledRazorTemplates.Dynamic.RazorEngine_0e5740b69a1c4d42979790ac728b7ca8.ExecuteAsync() at RazorEngine.Templating.TemplateBase.Run(ExecuteContext context, TextWriter reader) at RazorEngine.Templating.RazorEngineCore.RunTemplate(ICompiledTemplate template, TextWriter writer, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.DynamicWrapperService.Run(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass23_0.<Run>b__0(TextWriter writer) at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action1 withWriter)
at RazorEngine.Templating.RazorEngineServiceExtensions.Run(IRazorEngineService service, String name, Type modelType, Object model, DynamicViewBag viewBag)
at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
at Dynamicweb.Rendering.Template.RenderRazorTemplate()

Workaround / Additional Context:

Manually clearing the application cache via the backend, immediately resolves the issue, allowing the menu to render properly.

Menu.Creation.Issue.mp4

Metadata

Metadata

Assignees

Labels

AcceptedBugSomething isn't workingContentFor items related to Content

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions