GithubHelp home page GithubHelp logo

markjprice / apps-services-net7 Goto Github PK

View Code? Open in Web Editor NEW
150.0 150.0 60.0 57.67 MB

Repository for the Packt Publishing book titled "Apps and Services with .NET 7" by Mark J. Price

C# 28.45% HTML 69.50% CSS 1.17% JavaScript 0.86% PowerShell 0.02%

apps-services-net7's Introduction

Hi there 👋, I am Mark J. Price. Author. Programmer. Teacher.

  • 📖 You can get my books from Amazon or my publisher Packt or any good book store.
  • 🤔 I’m currently working on the .NET 8 editions of my best selling books, C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals, scheduled to publish on November 14, 2023, the 2nd edition of my book, Apps and Services with .NET 8, scheduled to publish on December 12, 2023, and Tools and Skills for .NET 8 Pros, coming in 2024.
  • 🌱 You can read a Q&A with me.
  • 💬 Ask me about any issues that you might be having with the code in my books.
  • 📫 How to reach me: markjprice is also my Gmail account name.
  • ⚡ Michelle McNamara: "It’s chaos. Be kind."
  • 🦣 I am on Mastodon.

What you should know about me

An ex-Microsoft Certified Trainer (MCT) with more than 30 years’ experience in the IT industry, including two years working full-time for Microsoft’s Training and Certification group in Redmond, USA, I specialize in training that leads to developer certifications.

I am eager to lead programming students, both experienced and new, into the challenging worlds of web, cloud, and mobile computing using a rare combination of thirty years’ education experience coupled with real world consulting and developing production systems for enterprises worldwide.

  • I live in Wiltshire, England.
  • I'm experienced in the practical use of Microsoft developer tools and technologies.
  • I'm dedicated to enthusiastic and dynamic training as a means of nurturing a lifelong love of programming.
  • I design, write, and deliver standardized and custom programming courses.
  • I'm adaptable and deal well with ambiguity in organizations of varying sizes and cultures.
  • I hold an Honours Bachelor’s Degree in Computer Science.

I have written a trilogy of guided learning books about C# and .NET:

See all my books on Amazon or Packt's website.

Education and Certification

Highly qualified and experienced.

Microsoft Certified Solutions Developer (MCSD)

Web Applications, Universal Windows Platform, Windows Store Apps Using C#, SharePoint Developer

Microsoft Specialist

Programming in C#, Programming in HTML5 with JavaScript & CSS3, Developing Microsoft Azure Solutions, Architecting Microsoft Azure Solutions

Microsoft Certified Trainer (MCT)

1993 - 2017

Computer Science (BSc. Hons.)

University of Bristol, June 1993

Professional Scrum Master I

Since January 2016

Google App Engine Qualified Developer

One of less than one hundred worldwide.

apps-services-net7's People

Contributors

markjprice avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apps-services-net7's Issues

MAUI Exception: A cycle occured while laying out GUI

Chapter: 19
Page Number: 724
Section Title: Implementing the Model-View-ViewModel pattern
Problem to fix:
I am running the MAUI app in debug mode with the service for categories running without debug. This is after the part where we add the categories page in to retrieve them from the service and display them in a carousel. I am getting an unhandled exception in the MAUI app:
"A cycle occurred while laying out GUI"
image

I cloned this repo, added the Chapter02 entity context project into the solution, and ran the project the same way with the files all from the repo, and I get the same error. Is this reproducible by anyone else?

I have been trying to figure this out for sometime, but it looks like others had similar issues and it was patched with a version of MAUI...

I am running VS Community 2022 v17.8.5

link crossorigin property must be camelCased

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 16
Page Number: 578
Section Title: Building Blazor components
Problem to fix: While troubleshooting why the Delete Database dialog box wouldn't open, I found an error message in the Developer Tools Console tab that contained the following - "... resource requires the request to be CORS enabled to check the integrity ...". Searching for this I found a post on StackOverflow stating that this is most likely caused by the crossOrigin property in the link element not properly camelCased. Once I corrected the links for bootstrap.min.css and bootstrap.min.js, the Delete Database dialog box started working properly.
Suggested solution: In step 17, fix the crossorigin property in the 2 new link elements so that it is crossOrigin.
Other useful information e.g. OS, coding tools, and so on:

Idea for next version chapter

One modern day enterprise technology the book forgets totally is infrastructure-as-code. I know it's easily a book of its own (as many of the other chapters in this book), but if you want to give a very brief introduction to yhis topic (with Azure), check out Farmer: https://compositionalit.github.io/farmer/

With less than 500 lines of code the enterprise infrastructure is backed-up in source control with proper version history, and re-deployed only by changes.

StrawberryShake - access to obj\\berry is denied - fix included

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 11
Page Number: 419
Section Title: Understanding Strawberry Shake
Problem to fix: When using VS2022 and StrawberryShake 12, compilation fails. Error message is "SS0006 Access to the path 'obj\berry' is denied." When building from the command line using dotnet build, the error message is "error SS0006: Method not found: 'Void StrawberryShake.CodeGeneration.CSharp.CSharpGeneratorSettings.set_RequestStrategy(StrawberryShake.Tools.Configuration.RequestStrategy)'"
Suggested solution: Add <StrawberryShake_State>$(MSBuildProjectExtensionsPath)berry</StrawberryShake_State> to a PropertyGroup for the project. Solution listed here: https://stackoverflow.com/questions/75693518/c-sharp-net-build-error-due-to-strawberry-shake-graphql-client-error-access.
Other useful information e.g. OS, coding tools, and so on:

Bad Page Numbering

Starting with page 232, the Table of Contents and all entries in the Index are 2 pages off.

String Interpolation and String Format in same line.

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 7
Page Number: 254
Section Title: Localizing the DayOfWeek enum
Problem to fix: WriteLine($"The day of the week is {0:dddd}.", DateTime.Now);
Suggested solution: WriteLine("The day of the week is {0:dddd}.", DateTime.Now);
OR
WriteLine($"The day of the week is {DateTime.Now:dddd}.");
Other useful information e.g. OS, coding tools, and so on:

ClickMeButton_Click missing in instruction 18

Chapter: 18
Page Number: 666
Section Title: Adding shell navigation and more content pages
Problem to fix: In step 18, the instructions state "Modify the Button element to give it a name of ClickMeButton and a new event handler for its Clicked event, as shown in Figure 18.13." In the figure, the event handler name is blank. There is and intellisense popup that says "" but no actual event handler name.
Suggested solution: Add the name to step 18 and update the image to include the name. Pressing Ctrl + Space autofills the name "ClickMeButton_Clicked" which is different from the name shown in step 20, which is "ClickeMeButton_Click."

Incorrect HTML element closing

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 16
Page Number: 578
Section Title: Building Blazor Components
Problem to fix: On step 17 the added markup elements closing is incorrect, should be /> instead of >. Minor thing as the IDE automatically makes the correction.
Suggested solution: Correct the markup to use /> instead of >
Other useful information e.g. OS, coding tools, and so on:

Comparing HTML Helpers and Tag Helpers

Chapter: 15
Page Number: 550
Section Title: Comparing HTML Helpers and Tag Helpers
Problem to fix: At the bottom of the page the statement says that all three examples generate an HTML element that looks like <a href="/home/privacy">View our privacy policy.</a> but they don't. Instead the first and last examples (I didn't do the middle one since it's the same as the first but has named parameters) generate the following HTML.

<a href="/Index/Privacy">View our privacy policy with an HTML Helper.</a>

<a href="/Home/Privacy">View our privacy policy with a Tag Helper.</a>

Suggested solution: Update the HTML Helpers lines to use Home instead of Index.

Other useful information e.g. OS, coding tools, and so on:
When browsing to the /Index/Privacy link, error 404 is displayed. When browsing to the /home/privacy link, the private page is displayed.

Chapter 2, Page 88 - Connection String

The book says I should see this string:

Data Source=.;Initial Catalog=Northwind;Integrated
Security=True;Multiple Active Result Sets=True;Connect
Timeout=10;Encrypt=True;Trust Server Certificate=True

What I actually see is this:

Data Source=.;Initial Catalog=Northwind;Integrated Security=true;TrustServerCertificate=true;

adding northwind script for postgresql in chapter 2

Hello Mark J. Price, I hope you are doing well. My recommendation is to add the Northwind script for PostgreSQL in Chapter 2. To accomplish this, you can refer to GitHub repositories or other articles. As a .NET developer, I try to use this technology stack on any Linux distro. Installing MS SQL Server often results in errors on-premises. Therefore, it would be beneficial to include other RDBMS systems like PostgreSQL or MySQL for Linux users. Thank you.

Chapter: 2
Page Number:
Section Title: understanding modern databases
Problem to fix:
Suggested solution: adding postgresql or mysql for linux users
Other useful information e.g. OS, coding tools, and so on: ubuntu 22.04

Chapter 17, Page 621, Bullet 6

This statement:

Results.Json(db.Categories.Include(c => c.Products))

appears to need a 3rd right parenthesis at the end:

Results.Json(db.Categories.Include(c => c.Products)))

I'm not sure why, but there's a compile error without it.

Chapter 16, Page 587, Bullet 3

Chapter: 16
Page Number: 587
Section Title: Building and testing a Blazor alert component
Problem to fix: ...in _Imports.cshtml
Suggested solution: ... in _Imports.razor

Image Sharp - Chapter 14

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 14
Page Number: 508-513
Section Title: Implementing a function that works with queues and BLOBs
Problem to fix:
The versions of the Image Sharp nuget package referenced to install seem to be out of date/Image Sharp made changes on their side. When I use version 2.1.3 of SixLabors.ImageSharp with 1.0.0-* or 1.0.0 of SixLabors.ImageSharp.Drawing I get the following errors on build (also removed ".nuget" folder to ensure a clean nuget package install):

/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Northwind.AzureFunctions.Services/Northwind.AzureFunctions.Services.csproj : error NU1605: Warning As Error: Detected package downgrade: SixLabors.ImageSharp from 2.1.5 to 2.1.3. Reference the package directly from the project to select a different version. [/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Chapter14.sln]
/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Northwind.AzureFunctions.Services/Northwind.AzureFunctions.Services.csproj : error NU1605: Northwind.AzureFunctions.Services -> SixLabors.ImageSharp.Drawing 1.0.0 -> SixLabors.ImageSharp (>= 2.1.5) [/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Chapter14.sln]
/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Northwind.AzureFunctions.Services/Northwind.AzureFunctions.Services.csproj : error NU1605: Northwind.AzureFunctions.Services -> SixLabors.ImageSharp (>= 2.1.3) [/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Chapter14.sln]
0 Warning(s)
1 Error(s)

It seems that the version must be updated to 2.1.5 on the ImageSharp.SixLabors. However once you upgrade to 2.1.5 the IPen and IBrush interfaces that are used no longer seem to be available.

S0246: The type or namespace name 'IPen' could not be found (are you missing a using directive or an assembly reference?) [/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Northwind.AzureFunctions.Services/Northwind.AzureFunctions.Services.csproj]
/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Northwind.AzureFunctions.Services/CheckGeneratorFunction.cs(58,13): error CS0246: The type or namespace name 'IBrush' could not be found (are you missing a using directive or an assembly reference?) [/Users/jimcampbell/jimcbell/learning/apps-services-net7/Chapter14/Northwind.AzureFunctions.Services/Northwind.AzureFunctions.Services.csproj]

This can be fixed by making the types for the objects used for drawing Pen and Brush:
Pen blackPen = Pens.Solid(Color.Black, 2); Pen blackThickPen = Pens.Solid(Color.Black, 8); Pen greenPen = Pens.Solid(Color.Green, 3); Brush redBrush = Brushes.Solid(Color.Red); Brush blueBrush = Brushes.Solid(Color.Blue);

One other thing is that the method signature for IImageProcessorContext no longer takes a TextOptions, it takes a RichTextOptions.
Screenshot 2023-12-24 at 8 50 20 AM

RichTextOptions inherits from TextOptions so this can be handled with an explicit cast:
image.Mutate(x => x.DrawText((RichTextOptions) textOptions,amount, blueBrush, blackPen));
or by declaring a RichTextOptions as the type for the textOptions object instead of a TextOptions:
RichTextOptions textOptions = new(font) { Origin = new PointF(100, 200), WrappingLength = 1000, HorizontalAlignment = HorizontalAlignment.Left };
image.Mutate(x => x.DrawText(textOptions,amount, blueBrush, blackPen));

Suggested solution: In problem.

My image after making these changes:
Screenshot 2023-12-24 at 9 02 37 AM

One more note, I only noticed because I am running this on a Mac instead of my normal Windows. The path separator is directly referenced in the CheckGeneratorFunction.cs with the Windows syntax () which will cause issues on Mac/Unix:

Here are some changes I made that may be useful (code from book is commented for reference):

// load the font file and create a large font FontCollection collection = new(); string pathToFont = System.IO.Path.Combine("fonts", "Caveat", "static", "Caveat-Regular.ttf"); FontFamily family = collection.Add(pathToFont); // FontFamily family = collection.Add(@"fonts\Caveat\static\Caveat-Regular.ttf");

// create blob in the local filesystem // string folder = $@"{System.Environment.CurrentDirectory}\blobs"; string folder = System.IO.Path.Combine(System.Environment.CurrentDirectory, "blobs");

string blobPath = System.IO.Path.Combine(folder,blobName); // string blobPath = $@"{folder}\{blobName}";
Not a major issue but wanted to drop it all here in case it saves someone else some time, thanks!

Chapter 6, Page 232, Bullet 3 - No Obsolete! Message

ID10T error. Missed adding {3} to the WritleLine for obsolete.

Chapter: 6
Page Number: 232
Section Title: 3
Problem to fix: Obsolete message not displaying
Suggested solution:
Other useful information e.g. OS, coding tools, and so on:
Type: Packt.Shared.Animal
Method: Speak (Animal)
-> Modified by Johnni Rasmussen on 9/13/2022
-> Modified by Mark Price on 8/22/2022
Method: SpeakBetter (Animal)
Method: GetType (Object)
Method: ToString (Object)
Method: Equals (Object)
Method: GetHashCode (Object)
Constructor: .ctor (Animal)

Blazor Client Not Showing Products Data

Chapter: 17
Page Number: 626
Section Title: Using the Radzen tabs, image, and icon components
Problem to fix:
For some reason none of the products are showing up in my blazor client. I have made updates according to the errata.
I can also see that the data is being returned by the minimal api in the network tab.
image
When I try to run this in debug mode to see for myself I get this exception:
System.IO.IOException: ' Received an unexpected EOF or 0 bytes from the transport stream.'
When I try to write the products to the console with a console.writeline statement, the categories no longer show up at all in the UI.
I have checked my packaging compared to the ones in the repository for the Server, Client, and Shared application and all are the same.

Here is my Client code:
protected override async Task OnParametersSetAsync() { Category[]? categoriesArray = null; // Web API service uses "Preserve" so // we must control how references are handled. JsonSerializerOptions jsonOptions = new() { ReferenceHandler = ReferenceHandler.Preserve, PropertyNameCaseInsensitive = true }; HttpClient client = httpClientFactory.CreateClient("Northwind.BlazorLibraries.ServerAPI"); string path = "api/categories"; try { categoriesArray = (await client.GetFromJsonAsync<Category[]?>( path, jsonOptions)); } catch (Exception ex) { Console.WriteLine($"{ex.GetType()}: {ex.Message}"); } if (categoriesArray is not null) { categories = categoriesArray.AsQueryable(); } }
This is my minimal api:
app.MapGet("api/categories", ( [FromServices] NorthwindContext db) => Results.Json( db.Categories.Include(c => c.Products))) .WithName("GetCategories") .Produces<Category[]>(StatusCodes.Status200OK);

I am not too positive where what to do for troubleshooting, I have also tested the api with rest client and it is returning the data fine, so I believe it is a client issue...

Missing using statement

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 11
Page Number: 411
Section Title: Using an ASP.NET Core MVC project as a GraphQL client
Problem to fix: In step 12 you say "... import the namespace for working with text encoding and for our Northwind entity models ..."; however, the using statement for Northwind is missing
Suggested solution: add the following statement - using Northwind.Mvc.GraphQLClient.Models;
Other useful information e.g. OS, coding tools, and so on:

Chapter 17, Page 621, Bullet 6

The book shows this code:

app.MapGet("api/categories", (
[FromServices] NorthwindContext db) =>
Results.Json(
db.Categories.Include(c => c.Products))
.WithName("GetCategories")
.Produces<Category[]>(StatusCodes.Status200OK);

The github shows this:

app.MapGet("api/categories", (
[FromServices] NorthwindContext db) =>
Results.Json(db.Categories.Include(c => c.Products),
jsonOptions))
.WithName("GetCategories")
.Produces<Category[]>(StatusCodes.Status200OK);

With either version, running the app produces No category found

Chapter 2, Page 91, Table-per-concrete-type (TPC) mapping strategy

Chapter: 2

Page Number: 91

Section Title: Table-per-concrete-type (TPC) mapping strategy

Problem to fix:

  • The SQL code shown for configuring the table-per-concrete-type (TPC) mapping strategy is not correct, because the two tables, Students and Employees, have a foreign key (FK) constraint for the People table, however that table is not needed in this mapping strategy.
  • Maybe this was copied over from the table-per-type (TPT) mapping strategy example on page 90, which has a similar SQL code.
  • The note box below the SQL code on page 91 talks about the PersonIds sequence, however that is not shown in the SQL code.
  • Besides, the SQL code in page 91 doesn't match with the output shown in page 99, step 17, which is the result of using the UseTpcMappingStrategy method, in the console app for using this strategy.

Suggested solution:

  • Remove the FK constraint on each table.
  • Add the CREATE SEQUENCE [PersonIds] in the SQL code of page 91.

I'm not sure if this is already fixed in recent editions of the book, or in the upcoming version for .NET 8.

By the way, thanks for the book, it's a formidable resource so far! I'm looking forward to buying the .NET 8 version soon.

Page 72 - Bullet 2: Stored Procedures menu item location

This paragraph:

In your preferred database tool, add a new stored procedure. For example, if you are using
SQL Server Management Studio, then right-click Stored Procedures and select Add New Stored
Procedure.

Might be better as:

In your preferred database tool, add a new stored procedure. For example, if you are using
SQL Server Management Studio, expand the Programmability node, then right-click Stored Procedures and select Add New Stored
Procedure.

Making the component a routable page component - Missing namespace

Chapter: 16
Page Number: 590
Section Title: Making the component a routable page component
Problem to fix: In Step 3, the instructions state to add

<NavMenu />

to the MainLayout.razor file. When doing this, VS22 automatically autocompletes it to

<Northwind.BlazorWasm.Client.Pages.NavMenu />.

This is because the NavMenu.razor file doesn't specify a namespace and the MainLayout.razor file doesn't import a namespace that the NavMenu.razor file should be using.

Suggested solution:
In step 4, add a line to include

@using Packt.Shared

at the top of the page.

In step 5, include a step to add

namespace Packt.Shared

at the top of the file.

English language in France ranked at 0.8

Please check that your issue is not already in the errata aka list of corrections and improvements. Please note that PRs will be ignored because code in the repo must match the print book already published. Please raise an issue instead so I can handle it appropriately. All issues will be entered into the errata once closed and fixed in the next book edition.

Chapter: 15
Page Number: 550
Section Title: Understanding the Accept-Language header
Problem to fix: In the third bullet after the paragraph explaining the Accept-Language syntax, it states:

  • fr-FR;q=0.8: English language in France ranked at 0.8.
    Suggested solution: It should say French, not English as shown below.
  • fr-FR;q=0.8: French language in France ranked at 0.8.
    Other useful information e.g. OS, coding tools, and so on:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.