ContosoCrafts icon indicating copy to clipboard operation
ContosoCrafts copied to clipboard

resolve null CS8603 Possible null reference return in JsonFileProductService

Open robertmaraan opened this issue 3 years ago • 2 comments

how to resolve possible null reference return in GetProducts

robertmaraan avatar Dec 13 '22 04:12 robertmaraan

also having this issue

Wombat45 avatar Dec 28 '22 23:12 Wombat45

Copy and Paste this code in your index.cshtml.cs file

public class IndexModel : PageModel { private readonly ILogger<IndexModel> _logger; public JsonFileProductService _productService; public IEnumerable<Product> Products { get; private set; }

    public IndexModel(ILogger<IndexModel> logger, JsonFileProductService productService)
    {
        _logger = logger;
        _productService = productService;
    }

    public void OnGet()
    {
        Products = _productService.GetProducts();
    }
}

After debugging i found that we did not give our field from class JsonFileProductService a value in the constructor.

kakembohenri avatar Jan 04 '23 06:01 kakembohenri