-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blazor NullReferenceException at AuthorizeViewCore.OnParametersSetAsync() in Published App but runs fine locally #41748
Comments
@v-milindm thanks for contacting us. Can you extend AuthorizeView (something like MyAuthorizeView) override OnParametersSetAsync() and check what is throwing the null reference exception? (Maybe write it to the output with console.writeline)? I suspect based on the code that is |
Hi @v-milindm. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Hello @javiercn, thank you for reaching out and the suggestions! I spent some more time debugging and placing some logging around wherever authentication data is being passed around starting from its source. Still, probably requires some more debugging and logging! I have updated my repo and checked-in the new changes here The exception shows as below from the custom logging message, need to see the stack trace probably but I think the error lies somewhere with the injected services otherwise the Here's the image for reference from the hosted environment: Strangely, the application works completely fine when I run locally, it only throws Here's a screenshot of running the application in my local environment: Do you know what might be causing this kind of behavior? Is it possible that recently something got changed with the application configuration/DI strategy and possibly my application is incorrectly configured? Thank you again for the help! |
@v-milindm thanks for the additional details. I didn't notice this when I looked at the code the first time. Replacing the authentication state provider in Webassembly is more involved than what you are doing there because it also handles the login/logout process so you need to extend AuthenticationService (which extends AuthenticationStateProvider) and register the same instance as an implementation of both services. If you are looking to capture additional information after the user has logged in, you should use https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/additional-scenarios?view=aspnetcore-6.0#customize-the-user |
Hi @v-milindm. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
Hello @javiercn, thank you again for the tip! I have been trying couple of things as per your suggestion and few more from some of the docs as well. I added the One of the things I tried is this one: name-claim-and-role-claim-mapping but didn't quite figure out a way to inject it in both Server and Client. Only Server got the data but Client was not getting anything. Regarding your suggestion,If possible, can you provide any documentation/guide on this, where you have mentioned in your comment that: What I am trying to do and what I have done so far,Some of these I might have already mentioned in my previous comments but here's bit more context,
The authentication part:Now, to implement authentication, I partially used this guide: hosted-with-azure-active-directory as the above linked document mentions to support prerendering with authentication after following the guidance in one of the Blazor WebAssembly security app topics, which is this one. Furthermore, on the authentication, specifically for Server project
I am not entirely sure if this was the correct/right approach and/or what I am doing is fine or not, but it worked fine, at least it used to work fine up until now, I guess. Please let me know if there is anything that can help me with this issue here! I have been trying to figure it out but seems like I am stuck onto something and maybe I am trying to implement something that goes against Blazor's design and/or is not supported. Let me know if you need any other information from my end. |
@v-milindm thanks for the additional details. I'm not sure I'm fully grasping what your concrete scenario is. It will help if you can (for a moment) forget about the implementation and describe the scenario you are trying to accomplish. From what I can tell/infer:
Does this describe your scenario? |
Hi @v-milindm. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@javiercn apologies for the late response on your questions, but you are on point about the scenario of my application and that is what I had done previously and I am still trying to do with my application for majority of the part. I think the only part that is little different is that I am not performing dual authentication i.e., Server asks for authentication and gets that information and then passes it to the Client as well. The Client, as far as I understand doesn't need to ask for authentication again as Server took care of it hence kind of avoiding the dual authentication there. Client, uses the same authentication. But, I can change this behavior if needed because I think this is the part where I have got the concept of authentication misunderstood probably due to maybe mixing it with pre-rendering concept, I guess?
Please let me know if you need any additional information here or if I missed anything while answering your questions as needed. |
@v-milindm thanks for the clarifications. The if you are authenticating the user on the server and passing down the authentication information to the client, you should avoid using any of the authentication related bits on either Instead, I would suggest you authenticate the user on the server (as you are doing) and pass down all the information to the client. Then on the client you implement your AuthenticationStateProvider to consume that information. In essence, |
@javiercn thank you for the help and suggestion! I tried as you suggested, and removed the Removed WebAssembly Authentication, which worked fine when tested locally. The application did Unfortunately, that still did not resolve my original problem, This is the implementation for CustomAuthStateProvider.cs |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
@v-milindm Not sure if it will impact anything, but this needs to be scoped. https://github.com/v-milindm/blazordebugapp/blob/master/blazordebugapp/Client/Program.cs#L41 I would suggest you try and debug through the webassembly application to see exactly where it is failing. |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
@javiercn thank you for the help once again! I was finally able to figure out the issue after adding some more logging into all of my start up services of the Client project. Unfortunately, I assumed incorrect and thought there was a problem with authentication/authorization. Apparently, this line right here: https://github.com/v-milindm/blazordebugapp/blob/master/blazordebugapp/Client/Services/UserRoleService.cs#L42 was not able to deserialize the JSON content into this object: https://github.com/v-milindm/blazordebugapp/blob/master/blazordebugapp/Shared/Models/UserIdentityClaims.cs. Also, it was working fine locally so that gave me hard time to figure out, otherwise this issue was quite simple, which took way longer than it should have to figure it out sadly. Stack trace:
invokeJSFromDotNet @ blazor.webassembly.js:1 To resolve this issue, Anyhow, this resolves my issue, so I am going to leave this closed. |
Is there an existing issue for this?
Describe the bug
Hello Team,
We have a web application for MSFT internal tenant. The app runs on
Blazor WebAssembly Core Hosted
model configuration following this approach: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/prerendering-and-integration?view=aspnetcore-6.0&pivots=webassembly and it is hosted on Azure App Service.It uses MSID platform authentication and is registered in AAD (Single tenant) as suggested in this guide: https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory?view=aspnetcore-6.0
Now,
System.NullReferenceException: Arg_NullReferenceException
atMicrosoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync()
after publishing to the Azure App Service.framework-dependent
andself-contained
but got the same error.Currently, this is a blocking issue as we are unable to deploy new changes/updates to any of the environments hosted on Azure App Service and its relative deployment slots.
Sample project
Blazor WebAssembly App
template withASP.NET Core Hosted
option enabled as that is the structure we are using in the application.Microsoft Identity platform
for authentication._Hosts.cshtml
I had to update therender-mode
toWebAssembly
fromWebAssemblyPrerendered
mode as the prerendered mode was giving me some trouble with using some of the injected parameters/services.Repository link: https://github.com/v-milindm/blazordebugapp
Please let me know in case you require any additional information or anything from my side.
I'd really appreciate it if someone can help me with this issue.
Thank you
Expected Behavior
The published version of the application should work as it is working when ran/debugged locally.
Steps To Reproduce
Here's the repository link: https://github.com/v-milindm/blazordebugapp
Used VS2022 to create the
Blazor WebAssembly App
, added minimal startup configuration as my application is using. Please find the below mentioned files, which are modified in the original templateASP.NET Core Hosted
model/structureMicrosoft Identity Platform
I haven't checked in my tenant-id and client-id in the
appSettings
so in case you require that then please let me know, I can create an Azure App Service for debugging/testing the published version.Also, for the MSID auth, the AAD (Single tenant) app registration is added as per this guide: https://docs.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/hosted-with-azure-active-directory?view=aspnetcore-6.0
Please update the following with the client-id and client-secrets, etc...
Once the above steps are done,
NullReferenceException
as soon as it loads up.Exceptions (if any)
The following exception appears in the published web application,
blazor.webassembly.js:1
System.NullReferenceException: Arg_NullReferenceException
at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState )
.NET Version
6.0.300
Anything else?
.NET SDK version: 6.0.300
Visual Studio 2022 Enterprise version: 17.2.1
Visual Studio Code version: 1.67.2
Azure App Service for hosting (.NET 6)
Azure DevOps for repository, code commit and CI/CD
Note: I have tried remote debugging with the Azure App Service but there is nothing that suggests what is causing the
AuthorizeView
component to throw null reference exception specifically in the published app.The text was updated successfully, but these errors were encountered: