`I recently installed the latest version of Visual Studio 2022 Version 17.10.3 and started working on a .NET 6 project. When I run my project, I encounter the following exception:
InvalidOperationException: No policy found: System.Object[].
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService.AuthorizeAsync(ClaimsPrincipal user, object resource, string policyName)
When I rollback to Visual Studio 2022 version 17.8.5, the project works without any issues. This leads me to believe that the problem might be related to the update to version 17.10.3
I have verified that the claim is present in the user’s claims. However, I still get the InvalidOperationException.
What could be causing this issue in Visual Studio 2022 version version 17.10.3?
How can I resolve this error so that my project runs correctly in the latest version of Visual Studio 2022 17.10.3?
Any help or insights would be greatly appreciated.
I noticed a potential difference in the AuthorizeAsync method implementation between the latest and older versions of the Microsoft.AspNetCore.Authorization namespace.
Latest Version:
public static Task<AuthorizationResult> AuthorizeAsync(this IAuthorizationService service, ClaimsPrincipal user, string policyName);
Older Version:
public static Task<AuthorizationResult> AuthorizeAsync(this IAuthorizationService service, ClaimsPrincipal user, string policyName)
{
if (service == null)
{
throw new ArgumentNullException(nameof(service));
}
if (policyName == null)
{
throw new ArgumentNullException(nameof(policyName));
}
return service.AuthorizeAsync(user, resource: null, policyName: policyName);
}
It seems like the newer version might be missing some checks or default parameters that were present in the older version. Could this be related to the issue I’m experiencing?
What could be causing this issue in Visual Studio 2022 version 17.9?
How can I resolve this error so that my project runs correctly in the latest version of Visual Studio 2022?
Any help or insights would be greatly appreciated.`