markjprice/cs11dotnet7

Found markup element with unexpected name 'Customers'. If this is intended to be a component, add a @using directive for its namespace.

johntempest opened this issue · 3 comments

Chapter: 16
Page Number: 723
Section Title: Building components using Blazor Server/Defining and testing a simple Blazor Server component
Step Number: 3
Problem to fix: RZ10012 ...unexpected name 'Customers' ...
-- Results in "Customers in Germany" and "Customers Worldwide" not being displayed in step 5.
Suggested solution: Add usings statement to bottom of _Imports.razor in Shared folder as follows:
@using Packt.Shared @* Northwind entities *@
Other useful information e.g. OS, coding tools, and so on: Microsoft Visual Studio Community 2022 (64bit) Version 17.5.1, Microsoft .NET Framework version 4.8.04161 as at 29/03/2023.

None of the steps on page 723 need to import the Packt.Shared namespace because you are not using the entity models yet. The error message you see is probably because either you named the Customers.razor file something different so it cannot find it when it looks for Customers, or you created it in a folder other than Pages so it's not found by default.

I did correctly name the Customers.razor file and it was created in the Pages folder, and I will have to concede that importing the Packt.Shared namespace was not necessary at that time. It still doesn't explain why the statements added in step 3, page 723, show up in the Visual Studio editor underlined with a green squiggle which lists the warning with the text supplied quoted in the heading to this issue I raised. I've now got as far as page 735 in the book and the warning squiggles still show on those lines added to the Index.razor file in step 3. So why the text "Customers in Germany/Customers Worldwide" didn't appear until after I'd made the adjustment is still unclear to me.

I find that there are many things that I still do not understand, and have to take on trust. Templates on creating files can be sometimes contain significant differences from the code presented in the book without any covering explanation. And sometimes making a link between the result and a statement of code which brings about that result is not always obvious -- unless perhaps you are well versed in the underlying software which is hidden from view.
I now feel wary about raising another issue, but I wonder why in Task Update (0n page 733) there is no statement : navigation.NavigateTo("customers"); as in the New and Delete functions to return to the /customers page. Without it, you get stuck on the page with an Update button that doesn't do anything any more, and the only way out is via the web browser's uri box.

Yes, I agree it's unclear to me as well as to why you got that warning message. It doesn't make sense to me.

FYI, there is already an errata item for the issue on page 733 here:
https://github.com/markjprice/cs11dotnet7/blob/main/docs/errata/errata.md#page-733---building-customer-create-edit-and-delete-components