Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

CslaPolicy not found when used in AuthorizeView #927

Open
Brannos1970 opened this issue Apr 11, 2020 · 3 comments
Open

CslaPolicy not found when used in AuthorizeView #927

Brannos1970 opened this issue Apr 11, 2020 · 3 comments

Comments

@Brannos1970
Copy link
Member

Question
I have several "AuthorizeView Policy=" statements in my razor pages the utilize the CslaPolicy.GetPolicy as such

@using Csla.Rules ... <AuthorizeView Policy="@(CslaPolicy.GetPolicy(AuthorizationActions.CreateObject, typeof(Shared.Customer)))"> ... </AuthorizeView>

However, I am getting the following error:

System.InvalidOperationException: The AuthorizationPolicy named: 'Csla:CreateObject|Shared.Customer, Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' was not found.
at Microsoft.AspNetCore.Authorization.AuthorizationPolicy.CombineAsync(IAuthorizationPolicyProvider policyProvider, IEnumerable`1 authorizeData)
at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.IsAuthorizedAsync(ClaimsPrincipal user)
at Microsoft.AspNetCore.Components.Authorization.AuthorizeViewCore.OnParametersSetAsync()
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Cannot access a disposed object.

Were there any configuration settings changed or something I am missing that would cause this error?

Version and Platform
CSLA version: 5.2.0
OS: Windows
Platform: Blazor

@rockfordlhotka
Copy link
Member

This happens in a repeatable manner, like all the time?

@Brannos1970
Copy link
Member Author

Yes. I removed the lines from all of the pages and replace them with if statements utilizing the HasPermission business rule and that worked.

@rockfordlhotka
Copy link
Member

I'd recommend looking through the book and ProjectTracker samples. I updated them over the past couple days and am not seeing this issue.

A lot of Blazor packages changed in the last couple previews, and for sure in client-side Blazor it is now necessary to explicitly call AddOptions during startup.

The BIG THING is that, for client-side Blazor, the private static method used to initialize per-type rules must now be public static, because otherwise the linker optimizes the method away during the build process.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants