2

Sitecore version: 9.0.2

Deployment model: PAAS Scaled

What I am doing: I am sending emails through scheduled tasks. The flow is working fine in the On-Premises standalone model.

In the higher PAAS Scaled environment, we got the following error:

Exception: System.InvalidOperationException
Message: Unable to resolve service for type 'Sitecore.EmailCampaign.Cd.Services.IClientApiService' while attempting to activate 'XXXXXX.Foundation.EXM.Services.ExmService'.
Source: Microsoft.Extensions.DependencyInjection
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet`1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)

I have tried both the approaches of creating the client as mentioned by Sitecore in the document.

I also came across this article https://andrewwburns.com/2018/08/17/avoiding-the-iclientapiservice/

But in both the approaches, the error is the same. Can you please guide me on this?

Thanks in advance.

  • Is your scheduled task running on the CM role of your scaled environment? – George Tucker Aug 18 at 13:51
  • @George: Yes it is running as scheduled task on the cm role. – NutsAndBolts Aug 18 at 13:59
1

You won't be able to resolve the IClientApiService from DI on a CM out of the box as the services are not registered (by design). The ClientApiService is essentially a wrapper to handle common functions that may need to be triggered from the CD roles. This will have worked in your lower environments as the service configurations will have been available in Standalone roles.

As the blog you referenced suggests, you could send straight to the message bus for automated messages and then the usual handlers will action the dispatch. The Sitecore documentation on sending programmatically may be of further help and can be found here: https://doc.sitecore.com/developers/exm/90/email-experience-manager/en/sending-email-campaigns-programmatically.html . It states a very similar solution as the blog you posted for sending of Automated messages (and regular campaigns if that is your aim)

IMessageBus<AutomatedMessagesBus> automatedMessageBus = 
ServiceLocator.ServiceProvider.GetService<IMessageBus<AutomatedMessagesBus>>();

AutomatedMessage automatedMessage = new AutomatedMessage()
{
    ContactIdentifier = contactIdentifier,
    MessageId = emailCampaignId
};
automatedMessageBus.Send(automatedMessage);

There should be no code trying to resolve IClientApiService in that solution. If you are still experiencing the same error, check your code to ensure you are not inadvertently trying to resolve the IClientApiService via DI.

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.