paulballard


Hello,

When I run my report from within visual studio 2005 it generates just fine.

However, when I run the report from the reporting services local web site I get the following error. What do I need to do to fix this (temporarily turning off .net security uusing caspol didn't work).

  • An error occurred while executing OnInit: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed



  • Re: Security exception when calling custom code from a report.

    paulballard


    Any ideas as this is urgent

    Any input would be greatly appreciated!!

    If any more information is required then please let me know.






    Re: Security exception when calling custom code from a report.

    centexbi

    I have a similar issue in SSRS where I am getting the current Windows UserID using the following code in Report Properties.Code. It works fine in Preview mode as expected but I get teh error below.

    Public Dim  MyUser As String = System.Environment.UserName

    The error is

    • Failed to load expression host assembly. Details: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. (rsErrorLoadingExprHostAssembly)

    I am doing this so that I can execute the report using a subscription as the global UserID does not permit one to run subscriptions. I have played around with permissions using the *.config files and Code Groups and named permission lists, but to no avail.

    If someone has already done this, can they post a suggestion

    Thanks






    Re: Security exception when calling custom code from a report.

    sunilv

    I got the same error when I run the report in server.

    Please somebody help





    Re: Security exception when calling custom code from a report.

    Mark Magnusson

    I have also run into this problem, and have tried everything i can find to resolve this situation however i am still coming up dry.

    Background info:
    I have designed and tested a report using a custom assembly in Visual Studio 2005. The report runs perfectly in Visual Studio.

    I uploaded the report to the report server, in the following directory:
    C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting Services\ReportServer\bin

    At this point i was able to access the report and run it fine from within the web report viewer of Microsoft CRM (the application that the report was designed for use with) however certain elements of the report would not render. I noticed that the elements in question are ones that rely on my custom assembly ( which accesses data from an SQL database running on the same SQL server as reporting services ).

    I then tracked that issue to the fact that my custom assembly was not signed and strongly named, and therefore didnt have the permissions required to access the SQL server data. So i generated a key and signed the assembly.

    I tried placing the assembly in the GAC after signing it, however when running the report it claimed that it could not find the assembly file, so i moved it back into the bin directory of the reporting server.

    Now when running the report i get the error: "Failed to load expression host assembly. Details: That assembly does not allow partially trusted callers. (rsErrorLoadingExprHostAssembly)"

    At this point i have hit a dead end, i need to find a solution to this issue as this report needs to be run from our local intranet. Any help on this would be greatly appriciated, thanks in advance.





    Re: Security exception when calling custom code from a report.

    Mark Magnusson

    Update:
    Still not working Sad and yes, i have added AllowPartiallyTrustedCallers() to the assembly, and yes i have tried Assert'ing for the permissions.

    Still at a standstill here, help!





    Re: Security exception when calling custom code from a report.

    Lukasz Pawlowski -- MS

    Rather than write code to do this, you can use the User!UserId property of the report to get the current user.

    -Lukasz






    Re: Security exception when calling custom code from a report.

    centexbi

    Can you tell us how we can use User!UserId and still setup a subscription That is why developers are trying to get around this issue.

    A typical scenario is that several users are allowed to look at a particular division's data. We want to cache the report once for all users in that division. The logged in user determines the security.

    Thanks





    Re: Security exception when calling custom code from a report.

    centexbi

    Here is my code that works with the necessary changes in RS config files.

    'Imports System.Security.Permissions

    <Assembly: AllowPartiallyTrustedCallers()>

    '<Assembly: EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME")

    Public Class ZPPSSolution

    ' get current Windows logged in user

    Public Shared Function GetWindowsUserName() As String

    Dim envPerm1 As New EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME")

    envPerm1.Assert()

    Return System.Environment.UserName

    End Function

    End Class





    Re: Security exception when calling custom code from a report.

    Lukasz Pawlowski -- MS

    User!UserID is tied to the owner of the subscription. So you need to create the subscription as the user you want it to execute as. This works for Interactive reports and standard subscriptions. This does not work for data-driven subscriptions. The reason is that in D-D subs, you want to send one report to many users. Therefore it does not make sense to use User!UserID to determine the data shown in that case :-).

    The approach of using the thread context falls apart in Subscriptions because the thread context is not the owner of the subscription since they are not present at the time the subscription is executed.

    -Lukasz