2

We have a local Sitecore 9.0.2 installation that is relatively vanilla. It is currently failing to load the Configuration Manager because of the following error message.

Server Error in '/' Application. Unable to activate type 'Sitecore.Marketing.xMgmt.Observers.Activation.PublishItemObserver`1[Sitecore.Marketing.Definitions.Campaigns.ICampaignActivityDefinition]'. The following constructors are ambigious: Void .ctor(Sitecore.Marketing.xMgmt.Observers.IPublishTargetResolver, Sitecore.Marketing.IItemRepositoriesSettings) Void .ctor(Sitecore.Marketing.xMgmt.Observers.IPublishTargetResolver, Sitecore.Data.Database) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Unable to activate type 'Sitecore.Marketing.xMgmt.Observers.Activation.PublishItemObserver`1[Sitecore.Marketing.Definitions.Campaigns.ICampaignActivityDefinition]'. The following constructors are ambigious: Void .ctor(Sitecore.Marketing.xMgmt.Observers.IPublishTargetResolver, Sitecore.Marketing.IItemRepositoriesSettings) Void .ctor(Sitecore.Marketing.xMgmt.Observers.IPublishTargetResolver, Sitecore.Data.Database)

This error goes away when we disable EXM in the Web.config.

More specifically, this error goes away if we comment out the Event Handlers loaded in the Sitecore.EmailExperience.ContentManagement.config listed here.

<events>
  <event name="item:added">
    <handler type="Sitecore.Modules.EmailCampaign.Core.ItemEventHandler, Sitecore.EmailCampaign" method="OnItemAdded" resolve="true" />
  </event>

  <event name="item:copied">
    <handler type="Sitecore.Modules.EmailCampaign.Core.ItemEventHandler, Sitecore.EmailCampaign" method="OnMessageCopied" resolve="true" />
  </event>

  <event name="item:created">
    <handler type="Sitecore.Modules.EmailCampaign.Core.RootItemEventHandler, Sitecore.EmailCampaign" method="OnRootCreated" resolve="true" />
  </event>

  <event name="item:deleted">
    <handler type="Sitecore.Modules.EmailCampaign.Core.RootItemEventHandler, Sitecore.EmailCampaign" method="OnRootDeleted" resolve="true" />
    <handler type="Sitecore.Modules.EmailCampaign.Core.ItemEventHandler, Sitecore.EmailCampaign" method="OnItemDeleted" resolve="true" />
  </event>

  <event name="subscriber:assigned" />
</events>

EDIT: This is happening in all environments now, so no longer environmental.

Obviously, the fix isn't to keep EXM disabled or to comment out these event handlers.

Does anyone have an answer as to how to solve ambiguous constructor issues, like this one above?

  • Did you deploy marketing stuff? – Vlad Iobagiu Apr 11 at 18:34
  • Figured it out. Very odd error, but it ended up being a red herring. – Pete Navarra Apr 11 at 19:02
1

This has been solved. The root issue was a Dependency Configuration that was trying to load some scoped items into the Container that essentially caused a null value to be placed into the container.

Turns out, the Sitecore Marketing Definition PublishItemObserver also inserts a "null" value into the container, causing all sorts of fun issues. Because there were two items in the container all looking for a "null" value, Dependency Injection was blowing up.

The reason that commenting out the event handlers for EXM "fixed" the issue is that Email Experience Manager seems to be the only module that resolves that particular object.

Here is the custom code in question that ended up causing the conflict:

            serviceCollection.AddScoped(p => Sitecore.Context.Database);
            serviceCollection.AddScoped(p =>
            {
                var personaFolderId = new ID("{EE66F221-9412-4EE1-BFAA-8918A08CD989}");
                return Sitecore.Context.Database.GetItem(personaFolderId).As<IStandardTemplateItem>();
            });

Because Sitecore.Context.Database is null, the scoped additions were blowing up the entire container.

I don't know enough about the specifics of Dependency Injection to explain further as to why this caused the issue, but in case anyone else happens upon this issue, verify all of your dependency configurations.

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.