#Error when using a custom assembly in SQL Reporting Services

OK, you're using SQL Server Reporting Services and you've created and deployed your custom assembly to 80\Tools\Report Designer and MSSQL\Reporting Services\ReportServer\bin just like you're supposed to. You have also edited rssrvpolicy.config and rspreviewpolicy.config per the information found at

https://msdn.microsoft.com/library/default.asp?url=/library/en-us/RSPROG/htm/rsp_prog_extend_install_25ia.asp

Still, no joy. You're able to preview your report in the report desginer and everything works great, but when you view the report in IE, you see #Error in every report item that you use a function from your custom assembly.

What's wrong and why does it work in the report designer? Well, it's likely you placed your CAS codegroup for the custom assembly in the wrong place within the rssrvpolicy.config file. When you do this, the entry will be ignored (and sometimes will even "break" reporting services in the same way that a munged machine.config will break asp.net) 

The reason why your custom assembly works in the designer is that we automatically grant full trust to any assemblies you call from the designer preview...so even if you do something wrong around configuring CAS, preview will probably still function.

The way you fix this problem is to paste your codegroup in a different place within the config file...I've found one foolproof spot in the *policy.config file that always works for me: on top of the second-to-last closing </CodeGroup> tag. This technique hasn't failed me yet:

                          // Your Stuff goes here….
</CodeGroup>
</CodeGroup>
</PolicyLevel>
</policy>
</security>
</mscorlib>
</configuration>