Code element in SSRS

SSRS's Code element supports the embedding of user-defined functions in reports.

You may find when you first attempt to preview reports containing Code elements that you receive an error like “Request for the permission of type…” – specifying whichever type you have referenced in your element. e.g. System.Security.Permissions.SecurityPermission when trying to call System.Security.Principal.WindowsIdentity.GetCurrent().

This is due to SSRS's Code Access Security feature and will require some config changes in a number of places. The location of the relevant config files may depend on your SQL version.

If you're simply previewing in Visual Studio the relevant config file is RSPreviewPolicy.config. In my defaujlt setup I found that the Report_Expressions_Default_Permissions CodeGroup was allocated PermissionSet Execution which isn’t enough – to allow report preview I changed it to FullTrust.