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:
Here is my very basic controller:
And here is my controller rendering definition:
Reproduction notes:
wwwroot
.FYI - everything is absolutely fine doing a view rendering - it's just controller renderings that seem to be causing a problem
A StackOverflowException is thrown when the execution stack overflows because it contains too many nested method calls. using System; namespace temp { class Program { static void Main(string[] args) { Main(args); // Oops, this recursion won't stop. } } }
Starting with the . NET Framework 2.0, you can't catch a StackOverflowException object with a try / catch block, and the corresponding process is terminated by default. Consequently, you should write your code to detect and prevent a stack overflow.
A Sitecore Controller Rendering is more complex than a View Rendering, mainly in that it requires a controller action. The rendering definition item includes both a controller name and controller action to execute. The controller action is then responsible for returning the correct view.
Once you have the settings open, expand 'Common Language Runtime Exceptions', expand 'System', scroll down and check 'System. StackOverflowException'. Then you can look at the call stack and look for the repeating pattern of calls.
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.
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!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With