Custom Assemblies - SQL Server Reporting Services

To reference custom assemblies in SSRS, several rules have to be followed in order for it to work.

Creating the Assembly

(1) Create a Class Library in Visual Studio

(2) Name the project CodeReportingLibrary

(3) Rename the class CodeReportingFunctions

(4) Import the System.Security.Permissions namespace

(5) Add the following code to the beginning of every method.

SqlClientPermission oPerm = new SqlClientPermission(
      PermissionState.Unrestricted);
   oPerm.Assert();

Using the Assembly

(1) Install the DLL in the folder C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies.

(2) Add a reference to the new assembly from your report via the Report menu > Report Properties > References tab.

(3) Call functions from this library via the following syntax: =CodeReportingLibrary.CodeReportingFunctions.MyFunction(Fields!CustomerId.Value.ToString())

Deploying the Assembly

(1) To deploy the DLL to the report server, copy it to the folder C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin.

(2) Adjust the security policy file for SSRS within C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\rssrvpolicy.config.

(3) Search for $CodeGen$ within the configuration file.

(4) Add the following code below that code group's ending element.
<CodeGroup 
     class="UnionCodeGroup"
     version="1"
     PermissionSetName="FullTrust"
     Name="CoDeMagSample"
     Description="CoDe Magazine Sample. ">
     <IMembershipCondition
       class="UrlMembershipCondition"
       version="1"
       Url="C:\Program Files\Microsoft SQL Server\
          MSSQL.3\Reporting Services\ReportServer\bin\
       CoDeReportingLibrary.dll"
     />
   </CodeGroup>