Sitecore Commerce 9 Updating Data Templates Gives Exception

Reading Time: 3 minutes

We have followed documentation on how to install Sitecore Commerce 9 on PaaS. We done bootstrapping and continued with remaining post installation steps.

We have also restarted all services, just in case.

We have refreshed Commerce Cache from the Sitecore “Commerce” ribbon in Content Editor.

Next step was to “Update Data Templates”.



Problem Description

When I hit the “Update Data Templates” button, we received this error:


Precise exceptions logged:

7300 09:38:26 ERROR Http Client Error Exception: System.Exception Message: An error occured while trying to contact the Commerce Service. Error code BadRequest

7300 09:38:26 ERROR GetList(id=’Catalogs’,type=’Sitecore.Commerce.Plugin.Catalog.Catalog, Sitecore.Commerce.Plugin.Catalog’,skip=0,take=1)?$expand=Items($select=Id) System.Exception: An error occured while trying to contact the Commerce Service. Error code BadRequest at Sitecore.Commerce.Engine.Connect.DataProvider.CatalogRepository.LogResponseError(HttpResponseMessage response, Boolean raiseError) at Sitecore.Commerce.Engine.Connect.DataProvider.CatalogRepository.d__24.MoveNext()

ManagedPoolThread #0 09:38:26 ERROR Exception Exception: System.Reflection.TargetInvocationException Message: Exception has been thrown by the target of an invocation. Source: mscorlib at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Sitecore.Reflection.ReflectionUtil.InvokeMethod(MethodInfo method, Object[] parameters, Object obj) at Sitecore.Jobs.JobRunner.RunMethod(JobArgs args) at (Object , Object[] ) at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) at Sitecore.Jobs.Job.DoExecute() at Sitecore.Jobs.Job.ThreadEntry(Object state) Nested Exception Exception: System.ArgumentNullException Message: Value cannot be null. Parameter name: key Source: mscorlib at System.Collections.Concurrent.ConcurrentDictionary`2.ContainsKey(TKey key) at Sitecore.Commerce.Engine.Connect.DataProvider.CatalogRepository.GetEntityView(String sitecoreId, String viewName, String forAction, String itemId) at Sitecore.Commerce.Engine.Connect.DataProvider.Templates.CatalogTemplateGenerator.BuildCatalogTemplates(Database database)

I navigated to “/sitecore/Commerce/Catalog Management/Catalogs” and field “SelectedCatalogs” was empty. You can see it on picture above on the bottom part. I suspected that this was causing trouble but couldn’t find out how to make it fulfilled.

As this field was empty, it was also causing trouble with Default Catalog Setting item located in “/sitecore/Commerce/Settings/Catalog/Default Catalog”:

Default catalog

I have clicked “Refresh Commerce Cache” couple of times on “Commerce” ribbon on and also restarted services in Azure PaaS. Nothing helped.

I could see catalogs for each environment without any problem in Business Tools (bizfx):

bizfx ok

So what was wrong with Content Editor and Commerce related items there?

Actually nothing wrong with Content Editor.

We were using default environment in Sitecore config that was not bootstrapped, therefore we received  exceptions. My colleague has not used default environment “HabitatAuthoring” during provisioning PaaS (as I did on prem) and configured our custom one. I bootstrapped and initialized only AdventureWorks and Habitat environment on PaaS. Therefore it was not working.

Solution 1)

Quick solution was to change value of “defaultEnvironment” element in Sitecore.Commerce.Engine.Connect.config to this correct (a.k.a default) value:


Solution 2)

Another option to solve this problem would be to create and bootstrap your own environment to meet your custom environment name in config. This would be either way done as next step / correct solution during development phase of your project. First solution solves the problem with OOTB / default values to showcase that Commerce 9 is installed and up and running.

Happy coding!

One comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.