Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.

 

SiteDefinition.Empty is not initialized

Vote:
 

The description of SiteDefinition.Empty says: This is a singleton instance which can be compared against using object comparison. However, if SiteDefinition.Empty is compared to itself, the result returned is false meaning this instance is not a singleton (SiteDefinition.Empty == SiteDefinition.Empty => false).

For comparison, on the .net-framework, SiteDefinition.Empty used to be initialized in WebIdentityInitialization initialization module.

#299102
Mar 28, 2023 5:34
Vote:
 

That's true, the EmptyDefinition property is never set

private static SiteDefinition EmptyDefinition;
// ...
public static SiteDefinition Empty
{
    get
    {
        return EmptyDefinition ?? new SiteDefinition
        {
            StartPage = ContentReference.EmptyReference
        };
    }
    internal set
    {
        EmptyDefinition = value;
    }
}

This property will always be recreated.

Create a custom class if you must have a singleton :P

public class SiteDefinitionCustom : IReadOnly<SiteDefinitionCustom>, IReadOnly
{
    private static SiteDefinition EmptyDefinition;

    public bool IsReadOnly { get; private set; }

    public static SiteDefinition Empty
    {
        get
        {
            // horrible but will work 😁
            if(EmptyDefinition is null)
            {
                EmptyDefinition = new SiteDefinition
                {
                    StartPage = ContentReference.EmptyReference
                };
            }
            return EmptyDefinition; 
        }
        internal set
        {
            EmptyDefinition = value;
        }
    }

    public object CreateWritableClone()
    {
        throw new NotImplementedException();
    }

    public void MakeReadOnly()
    {
        throw new NotImplementedException();
    }

    SiteDefinitionCustom IReadOnly<SiteDefinitionCustom>.CreateWritableClone()
    {
        throw new NotImplementedException();
    }
}
#299108
Mar 28, 2023 8:36
Vote:
 

Looks like a mismatch between xml doc and actual code. I will file a bug to Content platform team to correct it. thanks for bringing it to our attention 

#299111
Mar 28, 2023 10:01
Quan Mai - Mar 28, 2023 10:04
the bug is CMS-27266, but it is not yet made public
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.