nop 4.4 customization : Await PrepareProductOverviewModelsAsync method throwing null reference exception

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
2 anos atrás
Hello All,

I am moving customization changes from nopcommerce 4.3 to 4.4.0. 4.4 is completely built with async and await methods. I am new to this async await coding.
When I do simple method changes I am getting Object reference not set to an instance of an object error. I have created a simple method below after stripping other code to show the issue.

Below is the code

public virtual async Task<WishlistModel> PrepareWishlistModelAsync1(WishlistModel model, IList<ShoppingCartItem> cart, bool isEditable = true)
        {
            List<Product> lst1 = new List<Product>();
            lst1.Add(new Product { Id = 123, Name = "Product 1" });

            var products1 = await _productModelFactory.PrepareProductOverviewModelsAsync(lst1);

            return model;
        }

I am getting the object reference error at below line
var products1 = await _productModelFactory.PrepareProductOverviewModelsAsync(lst1);

I am unable to understand what mistake I am making. I tried to change from async method to the normal method but still getting the same error.

Thank you,
Sateesh M.
2 anos atrás
Hi,
First check you initialized factory (through constructor) properly.
  var products1 = await _productModelFactory.PrepareProductOverviewModelsAsync(lst1);
.

if yes,
Seems to be you created new product object by passing Id and Name. Here Id is pimary key of PRODUCT table. you can not set like this may be this product id(123) is not available and it thrown exception from PrepareProductOverviewModelsAsync.

You should debug this[PrepareProductOverviewModelsAsync] method.
2 anos atrás
Thank you so much Smiten Kalathiya.
I did a mistake in initialization of productmodelfacttory. Once corrected everything working fine.

Thanks,
Sateesh UM
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.