ContosoCrafts
ContosoCrafts copied to clipboard
resolve null CS8603 Possible null reference return in JsonFileProductService
how to resolve possible null reference return in GetProducts
also having this issue
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.