Showing posts with label Core. Show all posts
Showing posts with label Core. Show all posts

Tuesday, September 1, 2020

Sitecore XC 9.3 - Investigation and fix for Microsoft.OData.Client.DataServiceQueryException



Recently, We have found an issue while deploying the XC changes on a new machine, below are the error details Sitecore XC 9.3
 16164 19:56:24 ERROR Exception <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     <html xmlns="http://www.w3.org/1999/xhtml">     <head>     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />     <title> IIS 502.5 Error </title><style type="text/css"></style></head>     <body> <div id = "content">      <div class = "content-container"><h3> HTTP Error 502.5 - Process Failure </h3></div>      <div class = "content-container">      <fieldset> <h4> Common causes of this issue: </h4>       <ul><li> The application process failed to start </li>       <li> The application process started but then stopped </li>       <li> The application process started but failed to listen on the configured port </li></ul></fieldset>      </div>      <div class = "content-container">       <fieldset><h4> Troubleshooting steps: </h4>       <ul><li> Check the system event log for error messages </li>       <li> Enable logging the application process' stdout messages </li>       <li> Attach a debugger to the application process and inspect </li></ul></fieldset>       <fieldset><h4> For more information visit:       <a href="https://go.microsoft.com/fwlink/?linkid=808681"> <cite> https://go.microsoft.com/fwlink/?LinkID=808681 </cite></a></h4>       </fieldset>      </div>    </div></body></html> on Execute:https://commerceauthoring.xxx.com.dev.com/api/GetBulkStockInformation  
 16164 19:56:24 ERROR Application error.  
 Exception: System.Web.HttpUnhandledException  
 Message: An unhandled exception occurred.  
 Source: Sitecore.Mvc  
   at Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.ShowErrorMessage(ExceptionContext exceptionContext, ExceptionArgs args)  
   at Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.Process(ExceptionArgs args)  
   at (Object , Object )  
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)  
   at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)  
   at Sitecore.Mvc.Filters.PipelineBasedRequestFilter.OnException(ExceptionContext exceptionContext)  
   at System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)  
   at System.Web.Mvc.Controller.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)  
   at System.Web.Mvc.MvcHandler.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)  
   at Sitecore.Mvc.Routing.RouteHttpHandler.EndProcessRequest(IAsyncResult result)  
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)  
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
 Nested Exception  
 Exception: Microsoft.OData.Client.DataServiceQueryException  
 Message: An error occurred while processing this request.  
 Source: Microsoft.OData.Client  
   at Microsoft.OData.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)  
   at Microsoft.OData.Client.DataServiceContext.InnerSynchExecute[TElement](Uri requestUri, String httpMethod, Nullable`1 singleResult, OperationParameter[] operationParameters)  
   at Microsoft.OData.Client.DataServiceActionQuery`1.Execute()  
   at Sitecore.Commerce.ServiceProxy.Proxy.Execute[T](DataServiceActionQuery`1 query)  
   at Sitecore.Commerce.Engine.Connect.Pipelines.Inventory.GetStockInformation.Process(ServicePipelineArgs args)  
   at (Object , Object )  
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)  
   at Sitecore.Commerce.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)  
   at Sitecore.Commerce.Services.ServiceProvider.RunPipeline[TRequest,TResult](String pipelineName, TRequest request)  
   at Sitecore.Commerce.XA.Foundation.Connect.Managers.InventoryManager.GetStockInformation(CommerceStorefront storefront, IEnumerable`1 products, StockDetailsLevel detailsLevel, Boolean includeBundledItemsInventory, StringPropertyCollection propertyBag)  
   at Sitecore.Commerce.XA.Foundation.Connect.Managers.InventoryManager.GetProductsStockStatusFromConnect(CommerceStorefront storefront, ICollection`1 productEntityList, StringPropertyCollection propertyBag)  
   at Sitecore.Commerce.XA.Feature.Catalog.Repositories.PromotedProductsRepository.AdjustProductStockStatus(ICollection`1 productEntityList)  
   at Sitecore.Commerce.XA.Feature.Catalog.Repositories.PromotedProductsRepository.GetPromotedProductsJsonResult(IVisitorContext visitorContext, String productListId, String relationshipFieldId, String currentItemId, String currentCatalogItemId, Nullable`1 pageSize, Nullable`1 pageNumber, StringPropertyCollection propertyBag)  
   at lambda_method(Closure , ControllerBase , Object[] )  
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_6.<BeginInvokeAction>b__3()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)  
 16164 19:56:24 ERROR Exception <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">     <html xmlns="http://www.w3.org/1999/xhtml">     <head>     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />     <title> IIS 502.5 Error </title><style type="text/css"></style></head>     <body> <div id = "content">      <div class = "content-container"><h3> HTTP Error 502.5 - Process Failure </h3></div>      <div class = "content-container">      <fieldset> <h4> Common causes of this issue: </h4>       <ul><li> The application process failed to start </li>       <li> The application process started but then stopped </li>       <li> The application process started but failed to listen on the configured port </li></ul></fieldset>      </div>      <div class = "content-container">       <fieldset><h4> Troubleshooting steps: </h4>       <ul><li> Check the system event log for error messages </li>       <li> Enable logging the application process' stdout messages </li>       <li> Attach a debugger to the application process and inspect </li></ul></fieldset>       <fieldset><h4> For more information visit:       <a href="https://go.microsoft.com/fwlink/?linkid=808681"> <cite> https://go.microsoft.com/fwlink/?LinkID=808681 </cite></a></h4>       </fieldset>      </div>    </div></body></html> on Execute:https://commerceauthoring.xxxxx.com.dev.com/api/GetBulkStockInformation  
 16164 19:56:24 ERROR Application error.  
 Exception: System.Web.HttpUnhandledException  
 Message: An unhandled exception occurred.  
 Source: Sitecore.Mvc  
   at Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.ShowErrorMessage(ExceptionContext exceptionContext, ExceptionArgs args)  
   at Sitecore.Mvc.Pipelines.MvcEvents.Exception.ShowAspNetErrorMessage.Process(ExceptionArgs args)  
   at (Object , Object )  
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)  
   at Sitecore.Mvc.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)  
   at Sitecore.Mvc.Filters.PipelineBasedRequestFilter.OnException(ExceptionContext exceptionContext)  
   at System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)  
   at System.Web.Mvc.Controller.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)  
   at System.Web.Mvc.MvcHandler.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)  
   at Sitecore.Mvc.Routing.RouteHttpHandler.EndProcessRequest(IAsyncResult result)  
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)  
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
 Nested Exception  
 Exception: Microsoft.OData.Client.DataServiceQueryException  
 Message: An error occurred while processing this request.  
 Source: Microsoft.OData.Client  
   at Microsoft.OData.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)  
   at Microsoft.OData.Client.DataServiceContext.InnerSynchExecute[TElement](Uri requestUri, String httpMethod, Nullable`1 singleResult, OperationParameter[] operationParameters)  
   at Microsoft.OData.Client.DataServiceActionQuery`1.Execute()  
   at Sitecore.Commerce.ServiceProxy.Proxy.Execute[T](DataServiceActionQuery`1 query)  
   at Sitecore.Commerce.Engine.Connect.Pipelines.Inventory.GetStockInformation.Process(ServicePipelineArgs args)  
   at (Object , Object )  
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists)  
   at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)  
   at Sitecore.Commerce.Pipelines.PipelineService.RunPipeline[TArgs](String pipelineName, TArgs args)  
   at Sitecore.Commerce.Services.ServiceProvider.RunPipeline[TRequest,TResult](String pipelineName, TRequest request)  
   at Sitecore.Commerce.XA.Foundation.Connect.Managers.InventoryManager.GetStockInformation(CommerceStorefront storefront, IEnumerable`1 products, StockDetailsLevel detailsLevel, Boolean includeBundledItemsInventory, StringPropertyCollection propertyBag)  
   at Sitecore.Commerce.XA.Foundation.Connect.Managers.InventoryManager.GetProductsStockStatusFromConnect(CommerceStorefront storefront, ICollection`1 productEntityList, StringPropertyCollection propertyBag)  
   at Sitecore.Commerce.XA.Feature.Catalog.Repositories.PromotedProductsRepository.AdjustProductStockStatus(ICollection`1 productEntityList)  
   at Sitecore.Commerce.XA.Feature.Catalog.Repositories.PromotedProductsRepository.GetPromotedProductsJsonResult(IVisitorContext visitorContext, String productListId, String relationshipFieldId, String currentItemId, String currentCatalogItemId, Nullable`1 pageSize, Nullable`1 pageNumber, StringPropertyCollection propertyBag)  
   at lambda_method(Closure , ControllerBase , Object[] )  
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)  
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__11_0()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_1.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_6.<BeginInvokeAction>b__3()  
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)  
Solution -

I compared the solution dlls with the default setup and found diff in .Net core version - After updating the right version this issue has been resolved -


Basically in project solution, the reference has mentioned with 2.1.* and it was not the correct version.



Simple steps to configure - Sitecore.Commerce.Core.AutoApprovePolicy




If Sitecore XC sellable items are not getting published or it automatically removed (weird scenario) - It could be because you have not published sellable items correctly.

For the catalog import, there are a few options available - but if you want to use the Sitecore XC APIs, It's a good option to enable AutoApprovePolicy and remove once you finish your import.

If you are using the commerce core than you can set up this through the AutoApprovePolicy()

 public class ImportCatalogsCommand : CommerceCommand  
 {  
      public IImportCatalogsPipeline ImportCatalogsPipeline  
      {  
           get;  
      }  
      public ImportCatalogsCommand(IImportCatalogsPipeline importCatalogsPipeline, IServiceScopeFactory serviceScopeFactory)  
           : base(serviceScopeFactory)  
      {  
           Condition.Requires(importCatalogsPipeline, "importCatalogsPipeline").IsNotNull();  
           ImportCatalogsPipeline = importCatalogsPipeline;  
      }  
      public virtual async Task  
 <CommerceCommand> Process(CommerceContext commerceContext, IFormFile importFile, string mode, int batchSize, int errorThreshold, bool publishEntities = true)  
      {  
           using (CommandActivity.Start(commerceContext, this))  
           {  
                CommercePipelineExecutionContextOptions pipelineContextOptions = commerceContext.PipelineContextOptions;  
                ImportCatalogsArgument arg = new ImportCatalogsArgument(importFile, mode)  
                {  
                     BatchSize = batchSize,  
                     ErrorThreshold = errorThreshold  
                };  
                if (publishEntities)  
                {  
                     commerceContext.Environment.SetPolicy(new AutoApprovePolicy());  
                }  
                ImportResult importResult = await ImportCatalogsPipeline.Run(arg, pipelineContextOptions).ConfigureAwait(continueOnCapturedContext: false);  
                if (importResult != null)  
                {  
                     base.Messages.AddRange(importResult.Errors);  
                     base.ResponseCode = importResult.ResultCode;  
                }  
                else  
                {  
                     base.ResponseCode = commerceContext.GetPolicy  
      <KnownResultCodes>().Error;  
                }  
                if (publishEntities)  
                {  
                     commerceContext.Environment.RemovePolicy(typeof(AutoApprovePolicy));  
                }  
                return this;  
           }  
      }  
 }  
You can set up this directly in the policy during the import - If you are using the commerce API 

 { "$type": "Sitecore.Commerce.Core.AutoApprovePolicy, Sitecore.Commerce.Core", }