Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

resolve null CS8603 Possible null reference return in JsonFileProductService #23

Open
robertmaraan opened this issue Dec 13, 2022 · 2 comments

Comments

@robertmaraan
Copy link

how to resolve possible null reference return in GetProducts

@Wombat45
Copy link

also having this issue

@kakembohenri
Copy link

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

public class IndexModel : PageModel
{
private readonly ILogger _logger;
public JsonFileProductService _productService;
public IEnumerable 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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants