Last days I tried to write a sql server report. In the beginning everything was fine. Until – I wanted to call a custom method in a custom assembly of my project.
My first thought was adding the referenced assembly within the sql report and than calling the method in one of my textboxes.

As a result, I got many error messages that told me, that the method name does not have been declared. But the first error message was following:
Error while loading code module: ‘TpUtils, Version=1.90.0.0, Culture=neutral, PublicKeyToken=6d1c15bd239054aa’. Details: Could not load file or assembly 'TpUtils, Version=1.90.0.0, Culture=neutral, PublicKeyToken=6d1c15bd239054aa' or one of its dependencies. Das System kann die angegebene Datei nicht finden.
Ok, got it. It’s not enough to reference the custom assembly.
But where the hell is .NET searching for it? After raking up the internet I found the missing piece. The build process is searching for the custom assembly in a folder called “PrivateAssemblies”. The solution was to establish a post build event that copies the custom assembly to that folder.

Build succeeded! Now I can run the report – I thought. But the report viewer only showed the following message: The report references the code module … which is not a trusted assembly.

Ok. So raking up the internet again. The solution was to tell the report viewer, that our assembly is a trusted assembly. To do this, I had to call the method AddTrustedCodeModuleInCurrentAppDomain.
reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain
("TpUtils, Version=1.90.0.0, Culture=neutral, PublicKeyToken=6d1c15bd239054aa");
I compiled again and wow – the report came up. But instead of calling the method, the output console showed a message like that:
Warning: The BackgroundColor expression for the textbox ‘LogonName’ contains an error: Die Assembly lässt keine Aufrufer zu, die nicht voll vertrauenswürdig sind. (rsRuntimeErrorInExpression)
But what the hell … ? My Assemblies are fully trusted and signed, so go ahead! But .NET was stolid like a donkey. After searching the internet again, the solution I found was to put the following assembly attribute to my “signed and fully trusted” custom assembly.
[assembly: System.Security.AllowPartiallyTrustedCallers]
And now … Yeah. The report is rendering correctly.

But you may ask: “What is the method I wrote good for?” The simple answer. I have done this for colouring the rows by using a property of the bound objects. Which is a functionality that is not build in.
If you are interessted, here’s the custom method I wrote:
public static string ToKnownColor(int color)
{
return string.Concat("#" , Color.FromArgb(color).Name.Substring(2));
}
Crazy – how many problems can arise until this small piece of code could work.
Wish you a pieceful and bug free christmas.
Cheers
- Gerhard
February 4, 2008 at 9:18 pm
Thanks a million. Too bad people like yourself aren’t writing documentation for Microsoft. I constantly give them 1 star for documentation and leave nasty feedback about thier non-informative documentation.
February 8, 2008 at 4:26 pm
I didn’t get mine to work until I added the dll to the GAC, in addition. Wierd.
February 26, 2009 at 8:59 am
[...] http://jachman.wordpress.com/2007/12/19/how-to-use-custom-assemblies-with-reports/ Posted by zijincheng Filed in Reporting Service ·Tags: Reporting Service [...]
October 7, 2009 at 12:27 am
You saved me man,
a big thank you.
May 27, 2010 at 6:20 pm
I really so happy to find the resolve of that problem
Thans
November 24, 2010 at 3:05 pm
Excellent! This showed me what I needed to know about trusted assemblies where other descriptions had failed. Thank you!
January 20, 2011 at 7:28 pm
Your walkthrough was very useful, thanks a lot!
August 8, 2011 at 6:56 pm
Thanks a Zillion…….
May 13, 2013 at 10:01 am
ddddddddd
May 13, 2013 at 10:01 am
tttiiiiiiiiiimmmmmmmmmmeeeeeeeeeepppppppppppaaaaaaaaaaaaaaaaassssssssssssss