8

Hello i have been trying out the new xConnect in Sitecore 9. I am now trying to add custom facets to xConnect. To deploy these i need to create a json representation of my model.

I have created a class library with my facets and CollectionModel.

public class CollectionModel
{
    public static XdbModel Model { get; } = BuildModel();

    private static XdbModel BuildModel()
    {
        XdbModelBuilder modelBuilder = new XdbModelBuilder("DemoModel", new XdbModelVersion(1, 0));
        modelBuilder.DefineFacet<Contact, CartInfo>(CartInfo.DefaultFacetKey);
        modelBuilder.DefineFacet<Interaction, StoreInfo>(StoreInfo.DefaultFacetKey);

        return modelBuilder.BuildModel();
    }
}

[Serializable]
[FacetKey(DefaultFacetKey)]
class CartInfo : Facet
{
    public const string DefaultFacetKey = "CartInfo";
    public List<Product> Products { get; set; }
}

[Serializable]
[FacetKey(DefaultFacetKey)]
class Product : Facet
{
    public const string DefaultFacetKey = "Product";
    public Guid ID { get; set; }
}

[Serializable]
[FacetKey(DefaultFacetKey)]
class StoreInfo : Facet
{
    public const string DefaultFacetKey = "StoreInfo";
    public Guid StoreID { get; set; }
    public string ManagerName { get; set; }
    public List<Product> ActiveOffers { get; set; }
}

Now i am trying to convert this to json and export it to a file in a console application like so:

var model = Sitecore.XConnect.Serialization.XdbModelWriter.Serialize(CollectionModel.Model);
File.WriteAllText(CollectionModel.Model.FullName + ".json" , model);

When i run this i get the following error:

FileNotFoundException: Could not load file or assembly ‘System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263’ or one of its dependencies. The system cannot find the file specified.

Does anyone know what i am missing?

  • 1
    System.Interactive.Async is xConnect dependendcy which should be installed when Sitecore is deployed. A quick fix is to install the package from nuget: Install-Package System.Interactive.Async To find the reason why the dependency is missing you could check Sitecore's installation log file if any errors occurred during installation. – grg Nov 10 '17 at 11:02
  • I believe i might have a wrong version of something somewhere, after installing the package i still get the error – mark DE Jong Nov 10 '17 at 11:03
  • @SitecoreClimber how do you mean, i have not realy touched sitecore itself yet. I have added the same Sitecore.XConnect.dll to my console application and class library – mark DE Jong Nov 10 '17 at 11:15
  • @grg i have checked the logs and it has added the System.Interactive.Async without errors – mark DE Jong Nov 10 '17 at 11:19
  • can you reference model in this way : XdbModelBuilder modelBuilder = new XdbModelBuilder("DemoModel", new XdbModelVersion(0, 1)); modelBuilder.ReferenceModel(CollectionModel.Model); – Vlad Iobagiu Nov 10 '17 at 11:23
12

After playing around a little i found out that you have to add some references to your Console application. These can all be found in the bin folder of your xConnect or Sitecore project:

  • Newtonsoft.Json.dll
  • Sitecore.XConnect.dll
  • Sitecore.XConnect.Search.dll
  • System.Interactive.Async.dll
  • System.Interactive.Async.Providers.dll

This guide describes the creation and deployment of custom xConnect models very well:
https://citizensitecore.com/2017/10/17/xconnect-adding-custom-facets-in-sitecore-9/comment-page-1/#comment-323

  • 3
    You didn't do anything wrong Mark. Because you're creating a connection to xConnect outside of a Sitecore context there are some dependencies that are necessary that aren't present. I point those dependencies out in this post when initializing the XConnectClient. Keep in mind, those posts were written using the Technical Preview of SC9 - I need to update them to reflect changes to the Initial Release because you don't have to call File.WriteAllText(CollectionModel.Model.FullName + ".json" , model); anymore. – LonghornTaco Nov 10 '17 at 15:30
  • 2
    Oh, and thank you for referencing my post - glad it was helpful! :) – LonghornTaco Nov 10 '17 at 15:30

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.