2

I recently started seeing errors on my headless SXA CM instance every time a publish operation is performed:

One or more exceptions occurred while processing the subscribers to the 'publish:end:remote' event.
Exception[1]: System.InvalidOperationException 
Message[1]: Invalid event arg type: Sitecore.Data.Events.PublishEndRemoteEventArgs. Expected: SitecoreEventArgs 
Source[1]: Sitecore.Kernel 
   at Sitecore.Events.Event.ExtractParameters(EventArgs args)
   at Sitecore.Events.Event.ExtractParameter(EventArgs args, Int32 index)
   at Sitecore.XA.Foundation.Multisite.EventHandlers.SiteCacheClearer.OnPublishEnd(Object sender, EventArgs args)
   at Sitecore.Events.Event.EventSubscribers.RaiseEvent(String eventName, Object[] parameters, EventResult result)

I have isolated the issue to a custom JSS webhook that calls the Vercel API (this configuration is modelled after the pattern described in this post: https://miguelminoldo.fr/2021/10/18/deploying-sitecore-jss-next-vercel/

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
  <sitecore>
    <javaScriptServices>
      <publishWebHooks type="Sitecore.JavaScriptServices.AppServices.WebHooks.WebHooks, Sitecore.JavaScriptServices.AppServices">
        <hooks hint="list:AddWebHook">
          <hook type="Sitecore.JavaScriptServices.AppServices.WebHooks.WebHookDefinition, Sitecore.JavaScriptServices.AppServices">
            <name>Vercel - Publish Hook</name>
            <url>https://api.vercel.com/v1/integrations/deploy/prj_xxxxxxxx</url>
            <method>POST</method>
            <site>sitecoreverceldemo</site>
            <body></body>
          </hook>
        </hooks>
      </publishWebHooks>
    </javaScriptServices>
  </sitecore>
</configuration>

When I manually make a POST request to that endpoint, I get a valid response with a 201 response code. The response body is:

{"job":{"id":"xxxxxxx","state":"PENDING","createdAt":1711646911282}}

It is unclear what the implications are of this error, and it is also unclear why the error is firing in the first place.

2 Answers 2

0

This error message looks strange, it says that Sitecore calls an incorrect event handler method for the publish:end:remote event.

Please check your generated Sitecore config from /sitecore/admin/shownconfig.aspx and search for Sitecore.XA.Foundation.Multisite.EventHandlers.SiteCacheClearer, it should be configured as follows:

<events>
   <event name="publish:end">
      <handler type="Sitecore.XA.Foundation.Multisite.EventHandlers.SiteCacheClearer, Sitecore.XA.Foundation.Multisite" method="OnPublishEnd" />
      ...
   </event>
   <event name="publish:end:remote">
      <handler type="Sitecore.XA.Foundation.Multisite.EventHandlers.SiteCacheClearer, Sitecore.XA.Foundation.Multisite" method="OnPublishEndRemote" />
      ...
   </event>
   ...
</events>

Event handlers for publish:end and publish:end:remote should call different methods because they accept different argument types:

  • publish:end works with Sitecore.Events.SitecoreEventArgs
  • publish:end:remote works with Sitecore.Data.Events.PublishEndRemoteEventArgs

From the error message and stack trace it looks like the publish:end:remote event calls the method OnPublishEnd instead of OnPublishEndRemote, therefore it is unable to extract event arguments from the type PublishEndRemoteEventArgs because it expects to receive SitecoreEventArgs.

0

According to Sitecore support, this is a bug (reference #537078) that has been fixed in SXA 10.3:

The publish:end:remote event can throw an Invalid event arg type: Sitecore.Data.Events.PublishEndRemoteEventArgs error.

For educational purposes I will share their explanation:

The Sitecore.XA.Foundation.Multisite.EventHandlers.SiteCacheClearer processor for the publish:end:remote event is used to clear the cache of Sites when publishing. The ClearCache method of the Sitecore.XA.Foundation.Multisite.EventHandlers.SiteCacheClearer class clears all items of the following types:

  • SxaSiteProviders;
  • Website context factory;
  • SiteInfoResolver;

The impact of the exception is that the processor will not work and therefore the cache will not be cleared. This behavior will only affect the CM servers.

Sitecore Support did provide a workaround fix, but the recommendation is to upgrade to Sitecore 10.3 with SXA 10.3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.