Search code examples
c#reporting-services.net-4.6sharepoint-2016

SSRS Custom Assembly Doesn't Recieve Full Trust


I am trying to add in a custom assembly to a SSRS SharePoint Integrated reporting service. Howwever the custom dll keeps coming back as only partial trusted.

I have already gone into the rssrvpolicy.config file and added a code group that uses the UrlMembershipCondition evidence and pointed it to the reporting Bin where the DLL is, with PermissionSetName="FullTrust", and the DLL is stored in the C:\Program Files\Common files\microsoft shared\Web Server Extensions\16\WebServices\Reporting\bin

I then tried to add the DLL to the GAC but this also gave the same error coming back as only being partially trusted.

The reason this error is coming up is because I am trying to use a DLL that is fully trusted (In the GAC) that performs logging. It appears the logging DLL in the gac is trusted so I don't understand why this DLL isn't trusted when in the GAC or when explicitly told to be trusted.

I am using .Net 4.6 which I know had some changes to the CAS system.


Solution

  • I was finally able to work through the issue. My solution in this case was to use the 3.0 style CAS or level 1 (Microsoft Docs). I do not know if this is the best solution but it is a working solution.

    Step 1: In your project at the top of each .cs file make sure to specify you want to use the Level 1 security rule set by using the following attribute:

    [assembly: SecurityRules(SecurityRuleSet.Level1)]
    

    This attribute should go below your using statements but above the namespace keyword like this example.

    using Microsoft.SharePoint.Client;
    
    [assembly: SecurityRules(SecurityRuleSet.Level1)]
    
    namespace something.something{
       ...YOUR CODE HERE...
    }
    

    Step 2: Find out if you are using the reporting services in SharePoint integrated mode or Native mode.

    If you are using SharePoint 2016 integrated mode navigate to the following location and copy your DLL into the folder.

    C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\WebServices\Reporting\bin
    

    If you are using the Native mode then navigate to the following location and copy it into the folder.

    C:\Program Files\Microsoft SQL Server
    

    Then go through each numbered folder (IE 90,100,130, etc) until you find the Bin folder.

    I suggest placing your custom assembly here, instead of the GAC, since it is easy to grant full trust via the Reporting Services web config.

    Step 3: Finally go back up one level from the bin folder to where you see the web.config file for the reporting services. Within the reporting services find the following tag

    <trust level="something" originUrl\""/>
    

    Replace the level something with Full

    <trust level="Full" originUrl\""/>
    

    NOTE: Doing so will make all of the DLLs found in the Bin folder run with Full Trust as far as I can tell

    Perform an IISReset and test our your custom assembly. You should be able to have full trust and avoid any awful .Net 4.0 transparent code issues.


    I can't gaurentee that this will work for everyone. This whole .Net 4.6 CAS setup is very complicated and difficult to understand. Below are a list of Microsoft Docs that aided me in finding this answer.

    System.Security Critical Attribute

    Check for full trust in code