1

I'm trying to get the contacts but while creating an instance of xconnect client, I'm getting the following exception:

Type must have a parameterless constructor (not necessarily public) or a public constructor that only takes parameters that correspond to primitive types

Here is the pseudo code for reference.

using (XConnectClient client = SitecoreXConnectClientConfiguration.GetClient())
        {
          List<Contact> contacts = null;
          contact = client.Get<Contact>(new IdentifiedContactReference(AssemblyFacetInformation.ContactReference, "bcc746fa19cd6fddf0203aa443eebd11"), new ContactExecutionOptions(new ContactExpandOptions(AssemblyFacetInformation.ContactReference)));
          var contact = contacts.FirstOrDefault();
          var assemblyFacetInformation = contact.GetFacet<AssemblyFacetInformation>(AssemblyFacetInformation.Timezone);
          assemblyFacetInformation.TimeZone = windowsTimeZone;
          client.SetFacet(contact, AssemblyFacetInformation.Timezone, assemblyFacetInformation);
          client.Submit();

        }

My Custom model class

public class AssemblyFacetCollectionModel
  {
    public static XdbModel Model { get; } = BuildAssemblyModel();
    static XdbModel BuildAssemblyModel()
    {
      XdbModelBuilder xdbModelBuilder = new XdbModelBuilder("AssemblyFacetInformation", new XdbModelVersion(1, 0));
      xdbModelBuilder.ReferenceModel(CollectionModel.Model);
      xdbModelBuilder.DefineFacet<Contact, AssemblyFacetInformation>(AssemblyFacetInformation.DefaultFacetKey);
      return xdbModelBuilder.BuildModel();
    }
  }

This is my facet class

[FacetKey(DefaultFacetKey)]
  [Serializable]
  public class AssemblyFacetInformation : Facet
  {
    public const string IdentifierCookieName = "_assembly_visitor_id";
    public const string AnalyticsCookieName = "analytics_uuid";
    public const string MetroCookieName = "metro";
    public const string ContactReference = "Assembly_Visitor";
    public const string DefaultFacetKey = "AssemblyFacetKey";
    public const string Timezone = "Timezone";
    public AssemblyFacetInformation() { }

    [JsonProperty("metro")]
    public Metro metro { get; set; }
    [JsonProperty("geolocated_location")] //From "metro" Cookie
    public string GeoLocation { get; set; } //From "metro" Cookie
    [JsonProperty("distance_from_metro")]
    public float DistanceFromMetro { get; set; } //From "metro" Cookie
    [JsonProperty("latitude")]
    public float UserLatitude { get; set; } //From "metro" Cookie
    [JsonProperty("longitude")]
    public float UserLongitude { get; set; } //From "metro" Cookie
    [JsonProperty("prioritize_online")]
    public bool PrioritizeOnline { get; set; } //From "metro" Cookie
    //[JsonProperty("metro")]
    //public string ShopSession { get; set; } //From "_shop_session" Cookie
    [JsonProperty("time_zone")]
    public TimeZoneInfo TimeZone { get; set; }

  }

While debugging the process I found that exception originally thrown by the AssemblyFacetCollectionModel class on this line

      return xdbModelBuilder.BuildModel();

Did I miss something or doing anything wrong??

3
  • Try commenting out Metro and TimeZone fields temporarily. I think they are the reason of your issues.
    – Marek Musielak
    Nov 25, 2022 at 11:42
  • You were right @MarekMusielak these two fields were creating an issue. But now I'm getting this error. One or more local models conflict with the xDB service layer. 'AssemblyFacetKey, 1.0' does not have a remote version' Nov 25, 2022 at 12:29
  • You should not mix multiple questions in one post. Create new question describing the whole situation.
    – Marek Musielak
    Nov 25, 2022 at 13:09

1 Answer 1

0

The issue is with Metro and TimeZoneInfo types.

Either remove them or make sure that they are registered properly in your model and have proper constructors.

Read more about type restrictions here:

https://doc.sitecore.com/xp/en/developers/91/sitecore-experience-platform/the-xconnect-model.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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