0

After upgrade Sitecore Commerce from version 9.0.2 to 9.0.3, I'm facing a strange issue. When I want to create category or relation from code I got following error in Commerce Context:

Code: Warning 
CommerceTermKey: TransactionError
TransactionError Text: Transaction failed and rolled back

We're using OOTB methods. For the test I temporary switched CreateCategoryCommand for decompiled version which I put to the project for better debugging. I figure out that if I change following piece of code in CreateCategoryCommand from:

await createCategoryCommand.PerformTransaction(commerceContext, (Func<Task>)(async () =>
{
CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();
result = await ((IPipeline<CreateCategoryArgument, CatalogContentArgument, CommercePipelineExecutionContext>)this._createCategoryPipeline).Run(new CreateCategoryArgument(catalogId, name, displayName, description), (IPipelineExecutionContextOptions)pipelineContextOptions).ConfigureAwait(false);
}));

to:

CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.GetPipelineContextOptions();
result = await ((IPipeline<CreateCategoryArgument, CatalogContentArgument, CommercePipelineExecutionContext>)this._createCategoryPipeline).Run(new CreateCategoryArgument(catalogId, name, displayName, description), (IPipelineExecutionContextOptions)pipelineContextOptions).ConfigureAwait(false);

It starts working.

But interesting thing is that I don't have a problem with creating the Catalogs from code which as I checked also using PerformTransaction method.

To clarify, before tests I always cleaned and initialized commerce environment. I can also create categories via Postman and Business tools.

Looking forward to any ideas. Thanks in advance!

Update:

43 11:01:44 INFO Request starting HTTP/1.1 POST https://localhost:5000/Api/CreateCategory application/json; odata.metadata=minimal 161
3 11:01:44 INFO Successfully validated the token.
3 11:01:44 INFO AuthenticationScheme: "BearerIdentityServerAuthenticationJwt" was successfully authenticated.
3 11:01:44 INFO AuthenticationScheme: "Bearer" was successfully authenticated.
3 11:01:44 INFO Authorization was successful for user: "sitecore\Admin".
5 11:01:45 INFO Executing action method "CommerceProject.Import.Controllers.CommandsController.CreateCategory (CommerceProject.Import)" with arguments (["System.Web.Http.OData.ODataActionParameters"]) - ModelState is Valid
5 11:01:46 ERROR CtxMsg.Error.EntityNotFound: Text=Entity Entity-Category-103-369 was not found.
6 11:01:46 INFO MemCache.CreateCache.HabitatAuthoring.LocalizedTerms
6 11:01:46 INFO Management.block.getitemsbypath./sitecore/Commerce/Commerce Control Panel/Commerce Engine Settings/Commerce Terms/System Messages|en
25 11:01:46 ERROR PipelineAbort:Entity Entity-Category-103-369 was not found.
63 11:01:46 INFO Management.block.getitemsbypath./sitecore/Commerce/Commerce Control Panel/Commerce Engine Settings/Commerce Terms/BusinessTools/ViewPropertyNames|en
63 11:01:47 INFO Management.block.getitembyid.7f475f9d-341e-4a21-bec2-0f5f74987a3b: Language=en
63 11:01:47 INFO MemCache.CreateCache.HabitatAuthoring.Workflows
63 11:01:47 INFO Core.MemCache.CE.Miss.Workflow: ItemKey=Entity-Workflow-DefaultCommerceWorkflow
63 11:01:47 INFO Core.MemCache.CE.Add.Workflow: ItemKey=Entity-Workflow-DefaultCommerceWorkflow cache:HabitatAuthoring.Workflows
67 11:01:47 INFO SQL:block:persistentity.LocalizationEntity: EntityId=Entity-LocalizationEntity-05fe529156e04eb4857ad3cc2ff5875e
63 11:01:47 INFO SQL:block:persistentity.Category: EntityId=Entity-Category-103-369
62 11:01:47 INFO Executed action "CommerceProject.Import.Controllers.CommandsController.CreateCategory (CommerceProject.Import)" in 2811.7023ms
62 11:01:48 ERROR An unhandled exception has occurred while executing the request
System.NullReferenceException: Object reference not set to an instance of an object.
   at CommerceProject.Import.Services.LocalizationService.<SetLocalizations>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CommerceProject.Import.Services.CategoryImporter.<CreateCategoryAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CommerceProject.Import.Services.CategoryImporter.<CreateAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at CommerceProject.Import.Controllers.CommandsController.<CreateCategory>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterAsync>d__10.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeInnerFilterAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeFilterPipelineAsync>d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.<InvokeAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.<Invoke>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Sitecore.Commerce.Core.ClientCertificateValidationMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.<Invoke>d__7.MoveNext()
62 11:01:48 INFO Request finished in 3961.8688ms 500 text/html; charset=utf-8
  • Could you please share XC logs? – Andrei Paliakou Apr 20 at 7:32
  • Hi, I've updated the post. Null reference exception occurs because localization service can't find EntityId=Entity-LocalizationEntity-05fe529156e04eb4857ad3cc2ff5875e which should be created by CreateCategoryCommand but was rolled back. – szaf_xCommerce Apr 20 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.