WidgetFilter.cs null reference exception

Topics: Troubleshooting
Feb 24, 2011 at 5:16 PM

After installing some modules from the gallery we were getting a null reference exception in WidgetFilter.cs in the section under the comment "Build and add shape to zone".  This prevented the page from rendering.

We are still investigating which module is causing this problem but it doesn't seem right that a bad module should be able to crash the whole page rendering process.  

Suggest adding a try-catch-log around this code (like in the section above).

i.e. (around line 65 in current code)

 

            // Build and add shape to zone.
            var zones = workContext.Layout.Zones;
            foreach (var widgetPart in widgetParts) {
                try
                {
                    if (activeLayerIds.Contains(widgetPart.As().Container.ContentItem.Id))     // Exception can happen here
                    {
                        var widgetShape = _contentManager.BuildDisplay(widgetPart);
                        zones[widgetPart.Record.Zone].Add(widgetShape, widgetPart.Record.Position);
                    }
                }
                catch (Exception e)
                {
                    Logger.Warning(e, T("An error occurred adding widgetPart {0}", widgetPart.Title).Text); 
                }
            }

Coordinator
Feb 24, 2011 at 7:36 PM

Sounds like a good suggestion. Can you please file a bug and submit this patch?

Thanks!