I have constructed a Razor page TBB that uses a reference component on a page in order to render multiple component presentations. The reference component is used by some C# code to add a list of components that need to be rendered on the page. The TBB then renders the remaining components on the page.
The List of components are added as a package object by the C# code. The issue seems to be that depending on whether the list of components from the package gets rendered first or last there may be a publish failure. For instance, I have the reference component (CompA) and a another normal content component (CompB) on a page. If CompA is the first component on the page, publishing fails seemingly at the point the CompB presentation is rendered. If CompB is on the page first and therefore rendered first, publishing works fine. Also, template builder works fine no matter how the components are setup.
Below is a snippet of the Razor code for the TBB and the Error is at the bottom:
@{
foreach(var cp in ComponentPresentations){
@* only the component presentation that has this field will want to cycle through the package object and render list *@
if (cp.Component.Fields.ctAssociation != null )
{
@* cycle through list from Package and render component presentation for each component, template currently hard coded for testing purposes only *@
foreach(var comp in Package.DDCRESULT)
{
@RenderComponentPresentation(@comp.Id, "tcm:1102-59900-32");
}
}
else @*render all other comp presentations on page*@
{
@cp.RenderComponentPresentation();
}
}
}
Error:
tcm:Error ErrorCode="80040000" Category="18" Source="34ejsixk" Severity="1" xmlns:tcm="http://www.tridion.com/ContentManager/5.0"> tcm:Line ErrorCode="80040000" Cause="false" MessageID="16138"> ![CDATA[Unable to get rendered content of Page (tcm:2322-123358-64).]]> tcm:Line ErrorCode="80040000" Cause="true"> ![CDATA[Object reference not set to an instance of an object.]]>