wavemaster avatar image
0 Votes"
wavemaster asked ZhiLv-MSFT commented

Troubleshooting Controller in Blazor WASM project NET5 after app modernization

Redid a aspnet core 2.1 Blazor WASM project in NET5, just started from scratch as a I did not manage to follow the upgrade steps provided by Microsoft and we left with tens of error messages.

Initially the NET5 Blazor WASM app worked, but that was days ago and I have not been able to get it working again.

The code hits my .razor page and produces this error:
Unhandled exception rendering component: Value cannot be null. (Parameter 'source')
System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.Count[UserName](IEnumerable`1 source)
at AccountManager.Client.Pages.Accounts.OnInitializedAsync() in C:\Users\Robert\source\Repos\AccountManager\Client\Pages\Accounts.razor:line 89
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)


Adding breakpoints does nothing. The above error message pops up in the console and that is it. Without the call to the api, breakpoints work as they should in that code.

Ok, so something is up with the Controller. Comparing things with the aspnet core 2.1 app I see that this WASM project has different launchsettings between .Client and .Server, i.e. the SSL port is different, and when I run the app I have two browser windows.

The new NET5 WASM project has the same SSL port for .Client and .Server.

Is this how things are supposed to be in NET5?

How can I test my API to figure out what is not working right?

line89.png (46.8 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @wavemaster,

According to your code, you are using try...catch statement to catch the exception, try to set a break point here or check the console window to check if there has any exception or not? If catches the exception, check the detailed message. Besides, about the API method, you could also set a break point to check whether the method is executed or not.

0 Votes 0 ·

Break point inside the action method is not getting hit, and the same for the breakpoint in the catch (Exception ex).

There is no other exception on the console, and the network tab shows 200 on dotnet.5.0.6.js.1

What are your thoughts on the SSL port being the same for the server and client projects. Is that how things are supposed to be?96181-image-2021-05-12-215313.png

0 Votes 0 ·

Hi @wavemaster,

About the using the same port in server and client projects. Since, the HttpClient service in Blazor WebAssembly apps is focused on making requests back to the server of origin. So, it will use the same port.

In the Network tools, try to click the "All" request and check the request URL and the response value. Whether you could get the data from the API method? And you could try to move the http.GetJsonFromAsync() method to the OnInitializedAsync() method and check if the code works. Besides, it seems that there has an error, please check the console tool, whether the issue relates that or not.

Finally, here is an article about Call a web API from ASP.NET Core Blazor, you can check it.

0 Votes 0 ·
Show more comments

0 Answers