markjprice / cs12dotnet8

Repository for the Packt Publishing book titled "C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
620 stars 192 forks source link

Testing the WebAssembly components and service (ch15-blazor-wasm.md) #60

Open pmarangoni opened 4 months ago

pmarangoni commented 4 months ago
  1. I run both Northwind.WebApi and Northwind.Blazor and open the browser's developer tools.
  2. I navigate to https://localhost:5161/ and view the Console tab, and it is blank, unlike your description in step 5 which states: "note that Blazor WebAssembly has loaded .NET assemblies into the browser cache and that they take about 10.65 MB of space, as shown in Figure 16.7"
  3. Image 16.7 also shows a reference to blazor.webassembly.js, but my browser's sources tab doesn't show that file anywhere. Something is clearly wrong here.
  4. I can load customers when viewing Customers Worldwide or Customers in Germany, and I can also delete a customer. I cannot, however, edit or create a customer. Changes are not saved when editing, and I get client-side errors when trying to create a customer.
  5. In your step 7, you tell us to click on Customers Worldwide and view the Network tab to view the JSON response from the GET request, but the response shows "Failed to load response data: No data found for resource with given identifier" (even though the browser does in fact load the customer table). When I click on the Headers tab under Network, the Response Headers shows a content-type of text/html; charset=utf-8 instead of JSON.
pmarangoni commented 3 months ago

Just to add, this is a screenshot when trying to create a new customer. I enter values for each field, and after submitting the form (by clicking Create Customer), the page reloads with errors displayed under Customer Id and Company Name. Screenshot 2024-07-23 135654

pmarangoni commented 3 months ago

A little help please.

markjprice commented 3 months ago

I have updated the online section with new instructions and made the same changes to the PracticalApps solution code in the Northwind.WebApi, Northwind.Blazor, and Northwind.Blazor.Wasm projects. This should fix the problems. https://github.com/markjprice/cs12dotnet8/blob/main/docs/ch15-blazor-wasm.md

pmarangoni commented 2 months ago

Switching to the WebAssembly component

I was getting weird errors in the browser's console trying to get this to work.

Failed to start platform. Reason: TypeError: Cannot read properties of undefined (reading 'AspNetCore')

I found that others had similar issues and followed their advice and got it to work. Basically, I closed Visual Studio, then deleted the folders underneath the Northwind.Blazor.Wasm project's obj and bin folders. Restarted Visual Studio and it worked fine.

This is where I found the advice: https://github.com/dotnet/aspnetcore/issues/50755

I don't really have a lot of confidence in Blazor as a platform yet. I feel like it's still going through some nasty growing pains.

markjprice commented 2 months ago

I agree with you. To me, Blazor is still an "unstable" platform both in that it has more bugs than alternatives like MVC and that it is still evolving.

.NET 8 introduced huge changes in Blazor that meant the way I had designed my step-by-step instructions for the .NET 7 edition then broke with .NET 8 in ways that I discovered couldn't be easily fixed. When I first looked at the issues readers like you were having I tried to find some simpler fixes but ended up having to almost rewrite that whole section.

Blazor feels too much like the old Web Forms (.aspx) which tried to hide too much and ended up building a massive mess on top of web development.

I'm sorry I wasn't able to provide a solution earlier. I appreciate how frustrating that must have been for you and others. Thank you for your patience.

p.s. I will add the information you found about the Failed to start platform. issue to the page too.