5

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.]]>

3
  • Have you debugged through your C# TBB? It could be that there is a difference depending on the Rendering Mode? Commented Apr 12, 2013 at 10:52
  • Does tcm:1102-59900-32 exist?
    – johnwinter
    Commented Apr 12, 2013 at 14:33
  • 1
    I was also emailing with Alex Klock about this issue and he suggested checking the package object DDCRESULT to see if it is null in the cases where the failure is occurring. That was the issue. Of course, now I'm still not sure why when running the page through TB everything is processed correctly (DDCRESULT object is added), but when previewing page within CMI or publishing that is not the case. Commented Apr 15, 2013 at 12:54

2 Answers 2

4

I usually run into that type of error when I'm attempting to render a field in razor when it doesn't have a value.

One thing which I notice is this:

 @RenderComponentPresentation(@comp.Id, "tcm:1102-59900-32");

It's not necessary to to use @in your method. so you could just write

 @RenderComponentPresentation(comp.Id, "tcm:1102-59900-32")

I'd also think that the actual issue is with your Comp.Id I think that's what's coming back as an object, which explains the error message you're getting. So try converting it to a string:

@RenderComponentPresentation(comp.Id.ToString(), "tcm:1102-59900-32")
4

Ok, so what this really came down to was a bit of User Error. When using Template Builder (TB) the Page Template (PT) was being opened from the Publication it was created in. Not the one where the Page was being published (lower in the BluePrint). When opening the PT from the Page Publication the execution then failed in TB.

The real issue was that for some reason the C# TBB (assembly) code the PT used was localized in a Publication between the originating Publication and the one that housed the Page. A change had recently been made to the C# code, but because of that localization the Page Publication was not inheriting the code change. It instead continued to inherit the localized version (old version).

TBH, I'm not sure why the localization was done. I'm still looking into this, but I wanted to provide this update in order to put my question to rest.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.