[SOLVED] Class does not include a variable which it does


This Content is from Stack Overflow. Question asked by Email User

I’ve been making a webapp in Blazor and have been stuck on this error, which I cannot find any documentation of.

I wrote in my razor page:

    @foreach (App app in AppService.AllApps)

And the Visual Studio error says “‘App’ does not contain a definition for ‘Title’ and no accessible extension method ‘Title’ accepting a first argument of type ‘App’ could be found.” (The same for Price)

So I looked at my class, “App”, and it contained:

        public string Title { get; set; }

So, I don’t understand why it didn’t recognize that.

Thanks, in advance, any advice is helpful.


When you look in your Project files (Solution Explorer) you will see there is a file App.razor.

So your project has two different App classes, and that confuses both you and the compiler. In this case it preferred he App component.

The best approach is to rename your own App class to eg Application.

Option two is to use a qualified name, like @foreach (MyClasses.App app in ...) . I took a guess at the namespace here.

And option three is to rename the App.razor file but be aware it is used in a few different places, like Program.cs and _Host.razor / index.cshtml .

This Question was asked in StackOverflow by Email User and Answered by Henk Holterman It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?