About the author

Steven Harmansteven harman :: makes sweet software with computers!

For recent posts and more about me, scroll to the bottom.

Sponsors

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

Reporting Services + Your Custom Assembly = #Error. WTF?

OK, so you've spent the last (fill in some obscenely long time period) trying to get SQL Server Reporting Services to use your Custom Assembly for retrieving data from your application. But no matter what you try, you keep seeing #Error rather than your data when you run the report on the server.

By this point you've read countless white papers, tutorials, blog posts, etc... that outlining how the scenario should work*. That's right, you've added the necessary <codegroup> to your .config files. You've added references to your assembly from your report, and you've even made some example code (from the previously mentioned resources) work. You've tried everything you've read and everything you can think of.

I bet you've even tried banging your head on your desk/keyboard/wall hoping that magically it will just work. Well, it won't - so stop trying.

References Here's a question for you - are you calling the System.Data assembly from your custom assembly?

You can tell by taking a peek at your project's References - if you see System.Data then you're probably using it. You're probably using the assembly to pull some data out of your database... that's what I typically use it for.

So, assuming you are using the System.Data assembly from your custom code, are you explicitly asserting the permissions you have to the database connection? What does that mean?

It means that the runtime will throw a security exception unless you've explicitly asserted the permissions that you want for the resource - a database connection in this case. Open your source code and find any places in your custom assembly that you're trying to access a new database connection.

Now right before you declare that new connection, add the following code:

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

Next make sure that you've allowed your assembly to be called from a RS report by adding the following assembly decorator to your AssemblyInfo class:

[assembly: AllowPartiallyTrustedCallers]

Ok, now recompile your assembly and drop the binaries to the necessary locations. Then hit your RS server and run the report. With any luck you'll see your custom data, and not that nasty #Error text.

If that didn't work for you, I'm not sure what to say other than... try reverting each of the RS .config files back to their original state (you did back them up, didn't you?) and then start start over. Reconfigure each file to make sure you don't skip anything.

* = If you're looking for a quick how-to, try this article.

Technorati tags:

What others are saying.

# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar Doug Raney
Feb 02, 2007
Thanks very much for posting this solution. I followed your instructions exactly, and it worked the first time. It would have taken some time to troubleshoot this. Great save!

Sincerely,

New Fan.
# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar Steve Harman
Feb 02, 2007
Doug, glad I could be of help!

It took me a fair amount time to figure this out the first time. But that's what is so great about this here intarweb and Google - just a few keystrokes and we can learn from everyone else's trouble and toil.

Which reminds of a quote from Jon Galloway,
The answer is out there, even if I have to search every blog to find it.
# Troubleshooting Sql Reporting Services custom assemblies (extensions &amp;amp; what not)
Gravatar Lance's Whiteboard
Feb 05, 2007
I dont have time for a lengthy post, so here is some link-love for some great articles that have helped
# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar Larry Gilbert
Mar 06, 2007
This was big-time helpful, especially the link to the link to the how-to article. Twas there that I learned one must include System.Security in AssemblyInfo, using "imports" or "using" depending on your language. If using VB, the line one then adds to AssemblyInfo is

<Assembly: AllowPartiallyTrustedCallers()>

Thanks for the help.
# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar Steve Harman
Mar 06, 2007
@Larry: Happy to be of service :)

I know I spent what seemed like days scouring the web before I finally figured this out. That is what makes the techy-blogosphere so great... there is just a huge abundance of resources. The key is knowing where (and how) to look.

At any rate, glad this helped and thanks for the VB code for those readers using that particular dialect of the .NET Framework.
# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar MP Jatt
Nov 23, 2007
Thanks for this great Solution. It had helped me to get out of tough situation. Great Find
# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar sindhu
Jun 24, 2008
Hi,
Am getting the same #error in browser page rather the answer what i expected.
Can u say clearly how to write code groups in rs.config files and also if i write the
SqlClientPermission permission =
new SqlClientPermission(PermissionState.Unrestricted);
permission.Assert();
it shows Invalid '(' class,struct,or interface member declaration.
can u pls help me to solve this problem.
# re: Reporting Services + Your Custom Assembly = #Error. WTF?
Gravatar Dibakar
Jul 15, 2008
Hi,
I am facing the same problem ,but i could not able to solve this issue with your suggestion.
I am trying to access resouce file,here are my code :

public static string GetMessageDetails(string messageCode,string userCulture)
{
string errorMessage = string.Empty;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(userCulture);
Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(userCulture); ResourceManager resourceManager =
new ResourceManager("RptClassLibrary.Resource", Assembly.GetExecutingAssembly());

errorMessage = resourceManager.GetString("DefaultLink");
return errorMessage;
}

When i saw it in IE it is giving #Error.
Please help me.
Dibakar
Comments have been closed on this topic.