I don't understand why I am this error:'Pizza' does not contain a definition for 'Toppings' and no accessible extension method 'Toppings' accepting a first argument of type 'Pizza' could be found (are you missing a using directive or an assembly reference

Kevin Ear 20 Reputation points Microsoft Employee
2024-08-15T22:20:10.7933333+00:00

I am following the Microsoft learn doc and am simply copy and pasting https://learn.microsoft.com/en-us/training/modules/use-pages-routing-layouts-control-blazor-navigation/3-exercise-change-navigation-blazor-using-page-directive

It generates an error for me "'Pizza' does not contain a definition for 'Toppings' and no accessible extension method 'Toppings' accepting a first argument of type 'Pizza' could be found (are you missing a using directive or an assembly reference"

pizza.cs in model folder

PizzaStoreContaxt.cs

pizza.cs in data folder

I have the PizzaStoreContext.cs

Then I have two Pizza.cs classes.

One Pizza.cs class is in the Model folder

Other Pizza.cs class is in the Data folder

Blazor Training
Blazor Training
Blazor: A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.Training: Instruction to develop new skills.
7 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andrew Hall 80 Reputation points
    2024-08-16T00:17:41.6533333+00:00

    Hi Kevin,
    You've added another Pizza class and changed your folder structure slightly from the source repo.
    The pizza class in the 'data' folder does not have a Toppings property. The original class in the 'Model folder does.

    Because the folder structure is linked to namespaces, your PizzaStoreContext may now be in namespace 'BlazingPizza.Data' and can only directly see the Pizza class that has no toppings.

    You can remedy this by adding a using statement at the top of the class.
    'using BlazingPizza;' and commenting out the second Pizza class.

    or depending if you are wanting to use this new class, you may want to add a Topping property also.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.