Wrox Programmer Forums
|
BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7
This is the forum to discuss the Wrox book Professional SQL ServerReporting Services by Paul Turley, Todd Bryant, James Counihan, George McKee, Dave DuVarney; ISBN: 9780764568787
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 21st, 2005, 09:05 PM
Registered User
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default SecurityException - Custom Renderer CSV extension

Hello there!

Sorry it's a bit of a long one but the basic gist is that I'm having considerable trouble setting the right security settings for the Custom Renderer I've developed.
There's some background here for you, but if you're short on time feel free to skip to "The problem" below! Thanks heaps for reading.

The situation:
Delightfully, users can choose to export a report to CSV format. This is fantastic, because my client needs RS output in a CSV file format so they can import it into an existing tool of theirs.
The client likes to view this data by opening it in Excel before doing the import, to verify it is correct.
However, Excel won't correctly open a file exported into CSV format from RS because the CSV file is created with Unicode encoding, as opposed to ASCII encoding.

My solution:
I spent some time doing research on modifying settings for the CSV renderer. It has a property called "Encoding" which can take the value "ASCII" if I want it to. Calling this from a URL is easy: simply append "&rc:Encoding=ASCII" to the QueryString. However, obviously I don't want the client to have to go to this level of technical ability to get their nice Excel-compatible CSV file, nor is setting up a separate page of links a viable alternative as it requires a higher level of technical competence from the user.
So I decided to create a custom renderer. Initially I started to create one Implementing the IRenderingExtension Interface, and was going to custom-write all the code. However I soon discovered this was going to be a lengthy process, so I searched a little harder.
I discovered the Microsoft.ReportingServices.CsvRendering.dll assembly, which contains the type "CsvReport". So my plan for my custom renderer was as follows:
    1) Create an instance of CsvReport.
    2) Set CsvReport's encoding to ASCII.
    3) Render the CsvReport and return the result to the user.

The code:
    Imports Microsoft.ReportingServices.Interfaces
    Imports Microsoft.ReportingServices.Rendering.CsvRenderer
    Imports System.Collections.Specialized
    Public Class Renderer
        Implements Microsoft.ReportingServices.ReportRendering.IRende ringExtension
        Private m_csvrendCSVRenderer As CsvReport
        Public Sub New()
            m_csvrendCSVRenderer = New CsvReport
        End Sub
        Public ReadOnly Property LocalizedName() As String Implements IExtension.LocalizedName
            Get
                Return "CSV (Excel compatible)"
            End Get
        End Property
        Public Sub SetConfiguration(ByVal configuration As String) Implements IExtension.SetConfiguration
            m_csvrendCSVRenderer.SetConfiguration(configuratio n) 'NB this will be changed to insist on Encoding=ASCII in the final version
        End Sub
'etc... (Render, RenderStream, etc.)
    End Class

The installation:
    I build this custom renderer, and add it to RSReportServer.config:
        <Extension Name="CSVEXCEL" Type="Test.TestRendering.Renderer,Test.TestRenderi ng"/>
    I add the following security settings to rssrvpolicy.config:
        <CodeGroup
            class="UnionCodeGroup"
            version="1"
            PermissionSetName="FullTrust"
            Name="Test_TestRendering_Strong_Name"
            Description="This code group grants code signed with the TestRendering strong name full trust.">
            <IMembershipCondition
                class="StrongNameMembershipCondition"
                version="1"
                PublicKeyBlob="<public key for Test.TestRendering here>"
                />
        </CodeGroup>
    Later, I also added the same security settings above to rsmgrpolicy.config.
    Furthermore (running out of ideas because of the problem below) I've also used the mscorcfg.msc utility to configure the assembly .dll to have Full Trust.

The problem:
    I get the SecurityException shown in full below occurring in my RS logfiles when it attempts to load my custom renderer into the Export dropdown. The SecurityException doesn't occur if I remove the line "m_csvrendCSVRenderer = New CsvReport" from my code - however my custom renderer is obviously useless without that line. The error suggests that the CsvReport type requires any caller to have FullTrust - however giving my code FullTrust both system-wide AND in RS (as above) doesn't seem to have had any benefit. Is there any other restriction that CsvReport could be placing to stop me from being able to access it with my code?

    aspnet_wp!extensionfactory!1270!09/21/2005-23:59:28:: e ERROR: Exception caught instantiating report server extension: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: Request for the permission of type System.Security.Permissions.StrongNameIdentityPerm ission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
       at Test.TestRendering.Renderer..ctor()

    The state of the failed permission was:
    <IPermission class="System.Security.Permissions.StrongNameIdent ityPermission, mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                 version="1"
                 PublicKeyBlob="00240000048000009400000006020000002 40000525341310004000001000100272736AD6E5F9586BAC2D 531EABC3ACC666C2F8EC879FA94F8F7B0327D2FF2ED523448F 83C3D5C5DD2DFC7BC99C5286B2C125117BF5CBE242B9D41750 732B2BDFFE649C6EFB8E5526D526FDD130095ECDB7BF210809 C6CDAD8824FAA9AC0310AC3CBA2AA0523567B2DFA7FE250B30 FACBD62D4EC99B94AC47C7D3B28F1F6E4C8"/>

       --- End of inner exception stack trace ---
       at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
       at System.Reflection.Assembly.CreateInstance(String typeName)
       at Microsoft.ReportingServices.Diagnostics.ExtensionC lassFactory.AssertAndCreate(Assembly assembly, String typeName)
       at Microsoft.ReportingServices.Diagnostics.ExtensionC lassFactory.AssertAndCreate(Assembly assembly, String typeName)
       at Microsoft.ReportingServices.Diagnostics.ExtensionC lassFactory.GetNewExtensionInstance(String extensionName, String extensionType).
    aspnet_wp!configmanager!1270!09/21/2005-23:59:28:: e ERROR: An error occurred trying to load the 'CUSTOM_RENDERER' renderer. Not adding it to the export list. Details: System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.ReportingServices.WebServer.ViewerToolba rArea.RenderRendererWidgets(HtmlTextWriter outputWriter)


If anyone can shed any help upon what I can do to get around this issue, or any other way I can grant my code the Code Access Privileges to stop CsvReport hitting me with this SecurityException I'd really appreciate your help! I've also aired this question to the #sqlrs channel on irc.freenode.net:6667, which I've found to be an excellent resource for all RS developers, but to no avail at this stage.

Thanks in advance for any assistance, hopefully I can return the favour soon :)

-Geoff R G Williams
Primal Blaze Ltd.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do the SSRS - Custom Delivery Extension pnviv Reporting Services 1 March 17th, 2008 11:55 PM
Chapter 13 - Registering a Custom Data Extension MBryga BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 2 January 10th, 2008 11:49 AM
How to debug a SSRS 2005 Custom Data Extension MBryga BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 1 January 10th, 2008 11:33 AM
How to debug a SSRS 2005 Custom Data Extension MBryga Reporting Services 0 January 16th, 2007 01:57 PM
JTable Cell Renderer dontknowmuch Java GUI 1 August 3rd, 2005 10:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.