Null Reference Exception when widget references a content item that has been deleted.
I receive the following exception when I create a widget, select a content item, and then delete the content item. In my case, I created a custom module and am using the default designer.
[NullReferenceException: Object reference not set to an instance of an object.]
DynamicModule.ns.Wrapped_OpenAccessDynamicModuleProvider_71b59295779e47afa80daee85cb0ca48.GetDataItem(Type itemType, Guid id) +322
Telerik.Sitefinity.DynamicModules.DynamicModuleManager.GetDataItem(Type itemType, Guid id) +87
Telerik.Sitefinity.DynamicModules.Web.UI.Frontend.DynamicContentView.IsSingleItem() +277
Telerik.Sitefinity.DynamicModules.Web.UI.Frontend.DynamicContentView.CreateChildControls() +120
System.Web.UI.Control.EnsureChildControls() +83
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Control.PreRenderRecursiveInternal() +168
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974
You can easily reproduce this by following these simple steps:
1. Create a custom module.
2. Create a content item for the custom module.
3. Add the widget for the module you created to a page.
4. Click "edit" on the widget and under the content tab select "Only particular X only...". Select the content item you created.
5. Save your changes and publish the page.
6. View the page on the front-end. (it should not error)
7. Delete the content item you selected.
8. View the page on the front-end. (it throws an exception)
In my own code I have try/catches around GetItem calls on the DynamicModuleManager because it throws null reference exceptions if you try to get an item that no longer exists. Unfortunately, I have a lot of widgets that don't use my custom code and they use Sitefinity's default designers.
I am using Sitefinity 5.0.2523.0 SE. Is there anything I can do to mitigated this? On a large site there is not a good way for the client to know everywhere they referenced a content-item. I would rather Sitefinity handle its absence gracefully rather than blowing up the entire page.
Hi,
This issue was occuring in sitefinity 5.0 it is already fixed and there is no longer error thrown, when there is a single item selected which has been already deleted the widget will display no items as selected. Update to sitefnity 5.3 to get the fix.
Greetings,
Stanislav Velikov
the Telerik team