valdisiljuconoks / optimizely-advanced-contentarea

Optimizely content area renderer on steroids
Apache License 2.0
34 stars 14 forks source link

[BUG?] NullReferenceException when rendering a content-area after upgrading packages + .net target framework #76

Closed ds-epi closed 3 years ago

ds-epi commented 3 years ago

Dear Valdis,

I have upgraded packages EPiBootstrapArea and EPiBootstrapArea.Forms from 5.2.1 to 5.3.0. At the same time I have also updated the targetFramework from 4.6.1 to 4.8 and re-installed all nuget packages. Here's the full stack-trace from the server error:

[NullReferenceException: Object reference not set to an instance of an object.]
   EPiBootstrapArea.BootstrapAwareContentAreaRenderer.ProcessItemContent(String contentItemContent, ContentAreaItem contentAreaItem, IContent content, HtmlHelper htmlHelper, TextWriter originalWriter) +170
   EPiBootstrapArea.BootstrapAwareContentAreaRenderer.RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, String templateTag, String htmlTag, String cssClass) +616
   EPiServer.Web.Mvc.Html.ContentAreaRenderer.RenderContentAreaItems(HtmlHelper htmlHelper, IEnumerable`1 contentAreaItems) +201
   EPiBootstrapArea.BootstrapAwareContentAreaRenderer.RenderContentAreaItems(HtmlHelper htmlHelper, IEnumerable`1 contentAreaItems) +127
   EPiBootstrapArea.BootstrapAwareContentAreaRenderer.Render(HtmlHelper htmlHelper, ContentArea contentArea) +694
   ASP.util_views_shared_displaytemplates_contentarea_ascx.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in ..\Util\Views\Shared\DisplayTemplates\ContentArea.ascx:4
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +116
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +131
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +270
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +74
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +131
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +9489

I'll be happy to provide more information if needed. If I find the time I will replace the packages with the source-code and debug the issue but I hope this won't be necessary.

Thank you and regards,

DS

valdisiljuconoks commented 3 years ago

Hi,

Is it possible to jump back to 4.6.1? I don't think it's related to framework update, but who knows..

Debugging package would be the best bet here as it sounds that some weird data is coming in for the renderer who is not able to handle it.

ds-epi commented 3 years ago

Thank you for your superfast response :)

I really do not want to go back to the older .net framework. However, I went back to 5.2.1 for the EPiBootstrapArea packages and contentarea's work fine again. I highly doubt it has to do with the .net target framework (though not 100% sure).

I guess I'll have to debug it then. I will let you know if/when I find the issue.

Thanks!

valdisiljuconoks commented 3 years ago

Yeah, that's what I thought also. Super thanks for your efforts to hammer this bug out of source code.

ds-epi commented 3 years ago

None of the three methods set blockContentNode: image

image image image

ds-epi commented 3 years ago

And thus PrepareNodeElement is never called.. Adding this:

if (blockContentNode == null) { PrepareNodeElement(ref blockContentNode, contentItemContent); }

Like so: image

Fixes the issue (no error and content area items get rendered).

valdisiljuconoks commented 3 years ago

Great, adding a fix and rolling out new version.

ds-epi commented 3 years ago

Super, thanks !!