1

There is one Console application code for creating contact in xConnects in Sitecore 9.2 at https://doc.sitecore.com/developers/92/sitecore-experience-platform/en/create,-retrieve,-and-search-contact-and-interaction-data.html . But this is not compiling at my end. First of all below 2 lines showing red errors lines

CertificateHttpClientHandlerModifier options =
            CertificateHttpClientHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=15E6693B0AECB63DE57D991EC363CA462DC52432");
var certificateModifier = new CertificateWebRequestHandlerModifier(options);

but when I replace these lines with below ones, then this code is compiled.

        CertificateHttpClientHandlerModifierOptions options =
        CertificateHttpClientHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=864B202E730AF123AB857EE99824CB276B4866F1");

        var certificateModifier = new CertificateHttpClientHandlerModifier(options);

But now I am getting runtime error "The type initializer for 'Sitecore.XConnect.Collection.Model.CollectionModel' threw an exception." at line

var cfg = new XConnectClientConfiguration(new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);

Do anybody know how to compile this in Sitecore 9.2?

0

Its works when I run the code without debugging

using Sitecore.XConnect;
using Sitecore.XConnect.Client;
using Sitecore.XConnect.Schema;
using System;
using System.Threading.Tasks;
using Sitecore.XConnect.Client.WebApi;
using Sitecore.Xdb.Common.Web;
using Sitecore.XConnect.Collection.Model;
using System.Collections.Generic;
using Sitecore.Xdb.Common.Web;
namespace MyxConnectProgram
{
    public class Program
    {
        private static void Main(string[] args)
        {
            MainAsync(args).ConfigureAwait(false).GetAwaiter().GetResult();
        }
        private static async Task MainAsync(string[] args)
        {
            var options = CertificateHttpClientHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=864B202E730AF123AB857EE99824CB276B4866F1");
            var certificateModifier = new CertificateHttpClientHandlerModifier(options);
            var clientModifiers = new List<IHttpClientModifier>();
            var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20));
            clientModifiers.Add(timeoutClientModifier);
            var collectionClient = new CollectionWebApiClient(new Uri("https://XP9p2.xconnect/odata"), clientModifiers, new[] { certificateModifier });
            var searchClient = new SearchWebApiClient(new Uri("https://XP9p2.xconnect/odata"), clientModifiers, new[] { certificateModifier });
            var configurationClient = new ConfigurationWebApiClient(new Uri("https://XP9p2.xconnect/configuration"), clientModifiers, new[] { certificateModifier });
            var cfg = new XConnectClientConfiguration(new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);

            try
            {
                await cfg.InitializeAsync();
            }
            catch (XdbModelConflictException ce)
            {
                Console.WriteLine("ERROR:" + ce.Message);
                return;
            }
            using (var client = new XConnectClient(cfg))
            {
                Console.WriteLine("Connected:");
            }

            Console.ReadLine();
        }

    }
}

But if you try to debug the same program, you will get below error 'The type initializer for 'Sitecore.XConnect.Collection.Model.CollectionModel' threw an exception.'

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.