1

I'm getting below error in this code:

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

in below method to establish connection to xConnect.

  1. TypeInitializationException: The type initializer for 'Sitecore.XConnect.Schema.XConnectCoreModel' threw an exception.
  2. System.TypeInitializationException: 'The type initializer for 'Sitecore.XConnect.Collection.Model.CollectionModel' threw an exception.'
  3. FileNotFoundException: Could not load file or assembly 'System.Interactive.Async.Providers, Version=3.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' or one of its dependencies. The system cannot find the file specified.

public virtual XConnectClientConfiguration GetClientConfiguration(string collectionHost, string searchHost, string configHost, string thumbprint)
{
    //Set up the certificate used to connect to xConnect endpoints
    var options = CertificateHttpClientHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=" + thumbprint);
    var certificateModifier = new CertificateHttpClientHandlerModifier(options);


    //Set up timeout modifier for the client
    var timeoutClientModifier = new TimeoutHttpClientModifier(new TimeSpan(0, 0, 20));
    var clientModifiers = new List<IHttpClientModifier>
    {
        timeoutClientModifier
    };

    //Initialize the clients. Each requires the certificate in order to open the connection
    var collectionClient = new CollectionWebApiClient(new Uri(collectionHost + "/odata"), clientModifiers, new[] { certificateModifier });
    var searchClient = new SearchWebApiClient(new Uri(searchHost + "/odata"), clientModifiers, new[] { certificateModifier });
    var configurationClient = new ConfigurationWebApiClient(new Uri(configHost + "/configuration"), clientModifiers, new[] { certificateModifier });

    //Create the configuration object with all clients
    var cfg = new XConnectClientConfiguration(
        new XdbRuntimeModel(CollectionModel.Model), collectionClient, searchClient, configurationClient);

    return cfg;
}
0

Check in the bin folder of your website if you have those 2 dlls:

System.Interactive.Async.dll

System.Interactive.Async.Providers.dll

If not, add nuget package references in your project to them using version 3.0.0 (the one from your exception).

If you already have newer versions of the dlls in your bin folder, add assembly binding using the newVersion set to whatever you have, e.g.:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Interactive.Async" publicKeyToken="94bc3704cddfc263" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1" />
      <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" xmlns="urn:schemas-microsoft-com:asm.v1" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="System.Interactive.Async.Providers" publicKeyToken="94bc3704cddfc263" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1" />
      <bindingRedirect oldVersion="0.0.0.0-3.0.1000.0" newVersion="3.0.1000.0" xmlns="urn:schemas-microsoft-com:asm.v1" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>
1
  • 1
    now I'm getting below error post adding async.providers also. both have 5.0.0 version. 1. System.TypeInitializationException: 'The type initializer for 'Sitecore.XConnect.Collection.Model.CollectionModel' threw an exception.' 2. TypeInitializationException: The type initializer for 'Sitecore.XConnect.Schema.XConnectCoreModel' threw an exception. 3. TypeLoadException: Could not load type 'System.Collections.Generic.IAsyncEnumerator`1' from assembly 'System.Interactive.Async, Version=5.0.0.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263'.
    – Erwin Paul
    Feb 9 at 10:21

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.