This project has moved and is read-only. For the latest updates, please go here.

Security Exception

Feb 13, 2012 at 3:28 PM

I am getting a Security Exception in the following code:

var expressions = new List<Expression<Func<SPListItem, bool>>>();

...

var caml = Camlex.Query().WhereAll(expressions).ToString();

^ Exception occurs in the above line ^

Stack trace:

[SecurityException: Request failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission permThatFailed) +212
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +474
   System.Security.PermissionSetTriple.CheckSetDemand(PermissionSet demandSet, PermissionSet& alteredDemandset, RuntimeMethodHandle rmh) +105
   System.Security.PermissionListSet.CheckSetDemand(PermissionSet pset, RuntimeMethodHandle rmh) +71
   System.Security.PermissionListSet.DemandFlagsOrGrantSet(Int32 flags, PermissionSet grantSet) +59
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant, CompressedStack securityContext) +172
   System.Security.CodeAccessSecurityEngine.ReflectionTargetDemandHelper(Int32 permission, PermissionSet targetGrant) +65

I have added a Safe Control entry in the solution package for the assembly. The expressions doesn't try to access anything other than what is passed into the query i.e. the ID's of some items that must occur somewhere in the item.

Any clues?

Feb 13, 2012 at 3:43 PM

I managed to fix the Security Exception by changing the Deployment Target of the assembly from WebApplication to GlobalAssemblyCache.

My Safe Controls entry in Package > Advanced looks like this:

Namespace: CamlexNET
Type Name: *
Assembly Name: Camlex.NET.dll
Safe: Checked
Safe Against Script: Not checked.