I am updating this with some information on why we are checking. If you request a Sitecore element that does not exist, you get a null value, so it is easy to handle. However, if you request a Sitecore element that does not exist in that particular language, a versionless element is returned. This means that we must do this check, because otherwise Glass will return an empty class, which, I think, does not make much sense.
This answer will be a bit experimental.
First, in the Spherical.cs file, you need to disable the check:
protected void Application_BeginRequest() { Sitecore.Context.Items["Disable"] = new VersionCountDisabler(); }
Then we can transfer the check at a later date to the assembly line of the facility. First create a task:
public class FallbackCheckTask : IObjectConstructionTask { public void Execute(ObjectConstructionArgs args) { if (args.Result == null) { var scContext = args.AbstractTypeCreationContext as SitecoreTypeCreationContext; if (scContext.Item == null) { args.AbortPipeline(); return; }
Then, finally, register this task in the GlassMapperScCustom class:
public static void CastleConfig(IWindsorContainer container){ var config = new Config(); container.Register( Component.For<IObjectConstructionTask>().ImplementedBy<FallbackCheckTask>().LifestyleTransient() ); container.Install(new SitecoreInstaller(config)); }
I have not tested this, but should theoretically work <- disclaimer; -)
source share