5
votes

I am trying to do a simple controller rendering with Sitecore 8 and for some reason it's producing a StackOverflowException on the line within the main layout markup that contains the reference to the placeholder it is to be rendered in. This seems to crash the worker process, but you can see the stack overflow on debugging the process:

w3p crashStackOverflow

Here is my very basic controller:

Controller/View

And here is my controller rendering definition:

enter image description here

Reproduction notes:

  1. This is occurring in a vanilla Sitecore 8 installation (rev. 150427 -installed via SIM).
  2. The MVC project is also vanilla -created with empty ASP.NET project, then NuGetting in MVC 5.1.
  3. Web.config & Global added to project from the Sitecore site root in wwwroot.

FYI - everything is absolutely fine doing a view rendering - it's just controller renderings that seem to be causing a problem

3
I didn't get this solution for a while, when searched for unhandled microsoft .net framework exception w3wp sitecore stackoverflow, finally this question was a great help. - Sivalingaamorthy

3 Answers

3
votes

So the problem was actually pretty simple in the end.

Returning a ViewResult when the view is intended as a partial view (which all Sitecore renderings will be) then you must set the layout property in the markup to null:

@{
    Layout = null;
}

Otherwise MVC will try to wrap the layout file around it, which of course contains your Sitecore placeholder, which causes an infinite loop and crashes the worker process with a StackOverflowException.

So in the context of Sitecore, either return a PartialViewResult or return a ViewResult with the layout set as null.

1
votes

I guess there is something missing in placeholder setting, could you check in path sitecore/layout/placeholder setting?

There should be a placeholder key which you are trying to use.

Hope this will help

Cheers!!

1
votes

I think the issue can be with method View() being called without any parameters which can cause re-rendering the whole Sitecore page again.

Try to add parameter to View() like that:

return View("/Views/Courses/Index.cshtml");

Or whatever is the path of the view you want to return.


EDIT:

As @David Masters found, for some reason the issue is with calling View instead of PartialView method with the full path as a parameter. The correct code is:

return PartialView("/Views/Courses/Index.cshtml");