MarimerLLC / cslaforum

Discussion forum for CSLA .NET
https://cslanet.com
Other
31 stars 6 forks source link

CslaPolicy not found when used in AuthorizeView #927

Open Brannos1970 opened 4 years ago

Brannos1970 commented 4 years ago

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

` @using Csla.Rules ...

... ` 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 commented 4 years ago

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

Brannos1970 commented 4 years ago

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 commented 4 years ago

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.