I have an exception on the SecurityService on a page. The localisation works fine om the default page. But the error becomes on an other page with data and some lists. The localisation and authentication works fine also when the localisation change is done before entering the page. The page is authentication is for everyone, when i change the language then the SecurityService will throw an exception with a null value issued by:
public bool IsAuthenticated()
{
return Principal?.Identity.IsAuthenticated == true;
}
I cannot find why this routine throws the error.
Hi @RacketRebel,
I couldn't understand the steps to reproduce the problem. However it seems that Identity might be null in your case. Try changing the code like this:
public bool IsAuthenticated()
{
return Principal?.Identity?.IsAuthenticated == true;
}
Hi @korchev
The second ? is not the solution, and yes the identity is null, but only when changing the language.
I will make a screen capture, one with Radzen and one with JetBrains Rider, because MS Visual Studio is non longer supporting MacOS for .net8.
If the second ?
doesn't help then the problem is elsewhere. There isn't anything else in that method that can be null
. Try debugging to see where the actual exception is.
The next step, with the debugger step into , returns the exception, and the identity becomes null.
Unfortunately it is still not clear what could be causing this problem. Perhaps it is something used in the page itself (or layout). Did you customize the MainLayout in any way? Perhaps it uses something that could be null too. You can send us your application to info@radzen.com for further inspection.
I will send the application to by email
A few things to consider:
- The attachment size should be small - delete the bin and obj directories.
- The attachment should not contain .js files - delete any JS files otherwise our email provider would reject it.
You can also upload the application to a cloud storage provider (OneDrive, GoogleDrive etc.) and share a download link.
After watching the video I saw the exception is thrown by something put in a RadzenStack in the TransmissionBasic page. Are you accessing Security.User
or something else that could be null?
Not that i'm aware off, the page is accessible for everyone. Maybe is the route page the problem?
There is at least one variable e.g. transmission
which is used before being initialized. You can hide your form until everything needed is initialized/fetched from the database:
<RadzenTemplateForm Visible=@(transmission != null) TItem="ApiData" ...>
But why, the first call of the page does not give this exception and all data is initialised / fetched as expected, it only throws the null when changing the language on that page.
When you change the language a full browser refresh happens. This renders the page server-side and that's when the exception happens. Asynchronous code doesn't block rendering in Blazor thus you shouldn't access variables that may be null.
I agree, you should never acces variables that could be null, that's why I use the OnInitializedAsync() to init all variables, and in this case it's more than only one. By just picking this one Visible="@(transmissions != null)" solves at this moment the problem.
There are at least four other variables that are initialised at the OnInitializedAsync().
But still, i want to known what is then difference to display the page from the side bar, then it's also a full page rendering, shouldn't the change of the language follow the same route/steps?
The sidebar navigation uses Blazor routing. Changing the culture however requires a full page reload which bypasses the Blazor routing.
Thanks, Radzen and your support is perfect.