Start a new topic

NullReferenceException at SeacrhApi Module

After running Virtocommerce for 2 days I encountered this while browsing products or searcrhing products in storefront.

The seacrh Api is 1.0.1

Platform version is 2.12.0

Liquid error: Operation returned an invalid status code 'InternalServerError' { "message": "An error has occurred.", "exceptionMessage": "Object reference not set to an instance of an object.", "exceptionType": "System.NullReferenceException", "stackTrace": " at VirtoCommerce.SearchApiModule.Data.Services.ItemBrowsingService.SearchItems(String scope, ISearchCriteria criteria, ItemResponseGroup responseGroup)\r\n at VirtoCommerce.SearchApiModule.Web.Controllers.Api.SearchApiModuleController.SearchProducts(String scope, String storeId, ProductSearch criteria, ItemResponseGroup responseGroup)\r\n at VirtoCommerce.SearchApiModule.Web.Controllers.Api.SearchApiModuleController.SearchProducts(String storeId, ProductSearch criteria)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.AuthorizationFilterAttribute.d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()" }


Hi,


which search provider are you using, ElasticSearch or Lucene? Also what environment are you using, local or azure? If azure, can you provide us with url so we can troubleshoot it?


1 person likes this

I use Lucene one right now. 


It's a local environment. But open to public.

You can access here: http://dev.tks.co.th/entec-admin01

Sorry that I forgot to enclose storefront link


You can access storefront here: http://dev.tks.co.th/entec01

Thanks for the access, I downloaded import of the data and set it up locally and everything seem to work fine. It might have something to do with search indexes being corrupted, but need to confirm. Not sure how familiar you are with Virto Commerce, but it is possible to setup a debug version of search api module so it displays line where null reference is actually found. For that you need to connect to search api module github repository, download and compile it in debug mode and then simply copy debug file and dll to to app_data folder in the admin replacing the one that is already there. 


Let me know if you can do it, or need more step by step instructions. I will continue trying to replicate the exception in the meantime.

Actually after further investigation I found the following error in your hangfire instance. You can get there by going to http://dev.tks.co.th/entec-admin01/hangfire.


It looks like you are using Elastic Search and the new version requires latest Elastic Search server and won't work with 1.x version.


VirtoCommerce.SearchModule.Data.Providers.ElasticSearch.Nest.ElasticSearchException

Failed to remove indexes. URL:localhost:9200

VirtoCommerce.SearchModule.Data.Providers.ElasticSearch.Nest.ElasticSearchException: Failed to remove indexes. URL:localhost:9200 ---> VirtoCommerce.SearchModule.Core.Model.Indexing.IndexBuildException: Invalid NEST response built from a unsuccessful low level call on DELETE: /default
# Audit trail of this API call:
 - [1] BadResponse: Node: http://localhost:9200/ Took: 00:00:02.0032003
# OriginalException: System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:9200
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData)
# Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

   at VirtoCommerce.SearchModule.Data.Providers.ElasticSearch.Nest.ElasticSearchProvider.RemoveAll(String scope, String documentType)
   --- End of inner exception stack trace ---
   at VirtoCommerce.SearchModule.Data.Providers.ElasticSearch.Nest.ElasticSearchProvider.ThrowException(String message, Exception innerException)
   at VirtoCommerce.SearchModule.Data.Providers.ElasticSearch.Nest.ElasticSearchProvider.RemoveAll(String scope, String documentType)
   at VirtoCommerce.SearchModule.Data.Services.SearchIndexController.Process(String scope, String documentType, Boolean rebuild)

Thank you for good support. 


Now I moved back to Lucene and found that somebody accidentally delete Lucene folder in Appdata. Now I replaced that folder and everything start working again.


Glad it is working now. We need to provide better error message for elastic search however.

Login or Signup to post a comment