In Sitecore 9.3 Sitecore analytics, if I try and inherit Element, I see an obsolete message:

Assembly Sitecore.Analytics.Model, Version=

[Obsolete("Will be removed in the next version.")]
public abstract class Element : IElement, IValidatable
    protected Element();

    public bool IsEmpty { get; }
    protected IModelMemberCollection Members { get; }

    protected void EnsureAttribute<TValue>(string name);
    protected void EnsureCollection<TElement>(string name) where TElement : class, IElement;
    protected void EnsureDictionary<TElement>(string name) where TElement : class, IElement;
    protected void EnsureElement<TElement>(string name) where TElement : class, IElement;
    protected TValue GetAttribute<TValue>(string name);
    protected IElementCollection<TElement> GetCollection<TElement>(string name) where TElement : class, IElement;
    protected IElementDictionary<TElement> GetDictionary<TElement>(string name) where TElement : class, IElement;
    protected TElement GetElement<TElement>(string name) where TElement : class, IElement;
    protected virtual void OnValidate();
    protected void SetAttribute<TValue>(string name, TValue value);

What is the replacement of GetElement<TElement>, SetAttribute<TValue> and GetCollection<TElement> in Sitecore 9.3 xConnect.

Is there an example somewhere. Thanks in Advance!!


You would need to rewrite your code to not inherit from Element as it is removed in later versions. You can also take a look at the implementation in 10.1 for the models in the namespace Sitecore.Analytics.Model.Generated.

The methods EnsureAttribute, EnsureDictionary, EnsureElement were used in the constructor as a check to add the object to the collection if it didn't exist, but in the newer versions these aren't used anymore.

public ContactPhoneNumbers()
   this.EnsureAttribute<string>(nameof (Preferred));
   this.EnsureDictionary<IPhoneNumber>(nameof (Entries));

public ContactPhoneNumbers()

Instead of SetAttribute and GetAttribute you would need to read the values from the Fields collection, for example:

public string Country
      get => this.GetAttribute<string>(nameof (Country));
      set => this.SetAttribute<string>(nameof (Country), value);

Address.Fields uint16 = (Address.Fields) info.GetUInt16("f");
if (uint16.HasFlag((Enum) Address.Fields.Country))
  this.Country = info.GetString("c");

public string Country { get; set; }

The same would be for GetCollection:

public IElementCollection<ITagValue> Values => this.GetCollection<ITagValue>(nameof (Values));

[Obsolete("Deprecated in 10.0.0. Use Entries instead.")]
public IElementCollection<ITagValue> Values => (IElementCollection<ITagValue>) new ElementCollection<ITagValue>(this.Entries);

public IList<ITagValue> Entries => this._entries ?? (this._entries = (IList<ITagValue>) new List<ITagValue>());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.