"Illegal recursion detected: GetModel" error on the first request to SXA website


Description

An SXA site might fail to load for the first time with an unhandled exception. The website gets normally displayed after you have refreshed the page once or twice. The following message can be found in the logs:

Exception: System.InvalidOperationException
Message: Illegal recursion detected: GetModel
Source: Sitecore.Mvc
at Sitecore.Mvc.Common.RecursionPreventer..ctor(String title, Flag flag)
at Sitecore.Mvc.Presentation.Rendering.GetModel()
at Sitecore.Mvc.Presentation.Rendering.get_Model()
at Sitecore.XA.Foundation.Mvc.Wrappers.Rendering.get_Item()
...

Solution

To resolve the issue, consider one of the following options: