Developer forum

Forum » Ecommerce - Standard features » IndexBuilderExtender keeps giving me NullReferenceExceptions

IndexBuilderExtender keeps giving me NullReferenceExceptions

Peter Leleulya
Reply

When I try to get a Product Collection within the IndexBuilderExtender for a ProductIndexBuilder it always returns a nullreference exception.
Even when I use the use the GetProductsBySql api method and verify the input sql string does return products when I directly query on the database.

We also ran into this problem during the technical sessions in Alkmaar last december (with Lars Hejgaard Sørensen), but didn't find a solution then.
Does anybody know how to solve this problem?

 

using Dynamicweb.eCommerce.Products;

var sql = $"SELECT * FROM EcomProducts WHERE ........";     <!-- RUNNING THIS SELECT ON THE DB RETURNS ROWS
var products = Product.GetProductBySql(sql);      <-- THIS RETURNS A NULL REFERENCE EXCEPTION, WHY ???

 

var allProducts = Product.GetAllProducts();  <-- EVEN THIS RETURNS A NULL REFERENCE EXCEPTION, WHY ???


Replies

 
Nicolai Høeg Pedersen
Reply

The IndexBuilder runs in a seperate thread and does not have access to System.Web.HttpContext - and the product class happens to be dependant on httpcontext (because it needs context.language etc.).

So there are limitations to what you can do in that thread regarding the product instance.

So you might need to find the information directly - also not, that the core reason we do not use the product api in the indexer is performance. Be careful in that extender - if you index i.e. 100k products and add .5s per product it takes a LOT of extra time to index.

BR Nicolai

 
Peter Leleulya
Reply

OK ... This explains why ...
I'll go back to te drawingboard then ...
Thanks for your reply.

 

You must be logged in to post in the forum