WiseOwl Training - Established 1992 Wise Owl Training

Established May 1992
30 years in business
Wise Owl Training
30 years in business
See 482 reviews for our classroom and online training
SSRS custom assemblies using C# or VB
Part four of a six-part series of blogs

Reporting Services allows you to write functions in C# or Visual Basic, then reference these as custom assemblies. This blog shows how - and why - you might do this.

  1. Creating Custom Assemblies in Reporting Services
  2. Creating a Project, Class and Function in VB or C#
  3. Create and Deploy the Code DLL
  4. Referencing and Using Custom Assemblies in Reports (this blog)
  5. Post-Build Events to Help Deployment
  6. Debugging Custom Assemblies

Posted by Andy Brown on 03 August 2012

You need a minimum screen resolution of about 700 pixels width to see our blogs. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Referencing and Using Custom Assemblies in Reports

If you've been following this blog so far, you'll have created a C# or VB function, built it into a DLL file and copied this onto your development report server project.  Time now to use the function the DLL contains!

The actor's name missing

We'll create an expression to show the actor's name in proper case in the pink column.


Referencing the DLL Containing your Functions

Before you can use a function in a custom assembly within a report, you must first reference the custom assembly:

Show report properties dialog box

Create your report, and right-click on any edge to display its properties.


You can now choose to create a reference to your custom assembly.  First add a reference:

Adding a reference

Follow the numbered steps below to add a reference.

The steps to follow in the diagram above are:

  1. Choose to work with References.
  2. Choose to add a reference.
  3. Click on the build button to find your DLL (see diagram below).
  4. When you've created a reference, select OK.

It can take quite a while for the dialog above to appear properly the first time that you create a reference for a report.

To find your DLL, follow these steps:

Referencing a DLL

Follow these steps:


Note that it doesn't matter which DLL you reference above - reference either the one in the class library project or the one you've copied into your report server project.

Using Custom Assembly Functions within your Report

Finally, you can use functions that you've created within expressions in your report.  Choose to create an expression:

Creating an expression

Right-click on a textbox to create an expression for it in the usual way.


You can now use your function, providing that you refer to it correctly:

The function reference

You must use the name of the project, then the class, then the function (see below).


Any function that you call from a custom assembly must be fully qualified (that is, you must type in all the parts of the name):

Part of expression What it means Our example
Namespace The name of the DLL library (which should be the same as the name of your project). FunctionsC
Class The name of the class within this library. SampleClass
Function The name of the function you're calling. ProperCase

Don't let the red underlining put you off - if you've done everything correctly, this will work!

After all that, the results aren't quite what we want:

The results of the function

We really wanted to capitalise the first and last name!


Some Text Functions to Capitalise Names Properly

Since I'm feeling in a generous mood, here are some C# functions to extract the first name, last name and middle name from a name field:

public static string FirstName(string What)


// split into parts, and return first, in proper case/trimmed

string[] Parts = What.Split(' ');

string FirstPart = ProperCase(Parts[0].Trim());

return FirstPart;


public static string LastName(string What)


// split into parts, and return last, in proper case/trimmed

string[] Parts = What.Split(' ');

string LastPart = ProperCase(Parts[Parts.Length - 1].Trim())

return LastPart;


public static string Middle(string What)


// split into parts, and return middle bit

string[] Parts = What.Split(' ');

int i;

if (Parts.Length <= 2)="" {="">return ""; }

string s = Parts[1];

for (i = 2; i < parts.length="" -="" 1;="">


s += " " + Parts[i];


return s;


public static string ProperCase(string What)


// capitalises a name correctly (eg fReD becomes Fred)

string FirstLetter = What.Substring(0, 1);

string Remainder = What.Substring(1, What.Length - 1);

return FirstLetter.ToUpper() + Remainder.ToLower();


And here are the same functions using VB:

Shared Function FirstName(What As String) As String


'split into parts and return first, in proper case/trimmed

Dim Parts() As String = What.Split(" ")

Dim FirstPart As String = ProperCase(Parts(0).Trim)

Return FirstPart


End Function


Shared Function LastName(What As String) As String


'split into parts, and return last, in proper case/trimmed

Dim Parts() As String = What.Split(" ")

Dim LastPart As String = ProperCase(Parts(UBound(Parts)).Trim)

Return LastPart


End Function


Shared Function Middle(What As String) As String

'split into parts, and return middle bit

Dim Parts() As String = What.Split(" ")

Dim i As Integer

If UBound(Parts) < 2="">Then Return ""

Dim s As String = Parts(1)

For i = 2 To UBound(Parts) - 1

s &= " " & Parts(i)


Return s


End Function


Shared Function ProperCase(What As String) As String


'capitalises a name correctly (eg fReD becomes Fred)

Dim FirstLetter As String = What.Substring(0, 1)

Dim Remainder As String = What.Substring(1, What.Length - 1)

Return FirstLetter.ToUpper & Remainder.ToLower


End Function

I'll leave it to you, gentle reader, to work out how to refer to these functions in SSRS expressions (it should be straightforward).

You should now have working custom assemblies, but don't forget to copy the DLL files to your live report server folder when you deploy your reports, otherwise they'll work on the test server but not on the live one!

That completes creating custom assemblies, but I've included a couple of extra topics in the rest of this blog to make the whole process less fiddly and time-consuming: post-build events, and debugging.

This blog has 0 threads Add post