Please refer to this posting as a starting point - http://forums.lhotka.net/forums/p/10540/49324.aspx#49324
The suggestion to add a rule on the EditObject authorizationaction worked perfectly. However, I am now tryign to show/hide a UI link based on whether the execute action on the commandbase object is permitted. In order to do this, I added the following
public static bool CanEditObject ()
{
return Csla.Rules.BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.EditObject, typeof(CommandName
)); }
However when using CanEditObject , it throws the following exception
'Business.CommandName.CanEditObject()' threw an exception of type 'System.MethodAccessException' bool {System.MethodAccessException}
Not sure of what could be wrong here - but this code and unit test runs OK:
[Serializable] public class LookupCustomerCommand : CommandBase<LookupCustomerCommand> { public static bool CanEditObject() { return BusinessRules.HasPermission(Csla.Rules.AuthorizationActions.EditObject, typeof(LookupCustomerCommand)); } protected static void AddObjectAuthorizationRules() { BusinessRules.AddRule(typeof(LookupCustomerCommand), new Csla.Rules.CommonRules.IsInRole(AuthorizationActions.EditObject, "role1", "role2")); }
}
[TestMethod()] public void CanNotEditCommand() { Assert.IsFalse(LookupCustomerCommand.CanEditObject()); }
Is this v4.1.0? That is what I am running and I am continuing to run into this problem.
Which platform and UI technology do you get the exception on? .NET 4 or SL4 or WP?
Silverlight 4/ CSLA 4.1.0
Hi Ranjini,
I believe the solution for your problem is to change the AddObjectAuthorizationRules to be a public method rather than protected.
Limitations in reflection in Silverlight throws the exception when a method is not accessible for other classes (ie: protected and private).
Read more here: http://msdn.microsoft.com/en-us/library/stfy7tfc%28v=vs.95%29.aspx
Thanks!
Copyright (c) Marimer LLC