LocalReport.AddTrustedCodeModuleInCurrentAppDomain Method (String)

 

Note: This API is now obsolete.

Adds the supplied assembly to the list of assemblies that are trusted to execute in the current AppDomain.

Namespace:   Microsoft.Reporting.WinForms
Assembly:  Microsoft.ReportViewer.WinForms (in Microsoft.ReportViewer.WinForms.dll)

Syntax

[ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")]
public void AddTrustedCodeModuleInCurrentAppDomain(
    string assemblyName
)
public:
[ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")]
void AddTrustedCodeModuleInCurrentAppDomain(
    String^ assemblyName
)
[<ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")>]
member AddTrustedCodeModuleInCurrentAppDomain : 
        assemblyName:string -> unit
<ObsoleteAttribute("This method requires Code Access Security policy, which is deprecated.  For more information please go to https://go.microsoft.com/fwlink/?LinkId=160787.")>
Public Sub AddTrustedCodeModuleInCurrentAppDomain (
    assemblyName As String
)

Parameters

  • assemblyName
    Type: System.String

    The name of the assembly to be added.

Remarks

Important

This method is deprecated for .NET Framework 4 because the code access security (CAS) feature it relies on is deprecated in .NET Framework 4. Instead, the ReportViewer control always executes in the sandboxed application domain. You should use AddFullTrustModuleInSandboxAppDomain and SetBasePermissionsForSandboxAppDomain. If you want to continue to use this method with .NET Framework 4, you must use the in the Web.config file of your ASP.NET application. Otherwise, this method will throw an InvalidOperationException.

This method will continue to work with .NET Framework 3.5.

For more information, see Code Access Security Policy Compatibility and Migration.

Expressions in the report will be executed in the current AppDomain with only the Execution security permission flag. By default, custom assemblies are not allowed in this mode. The AddTrustedCodeModuleInCurrentAppDomain method can be used to allow the use of custom assemblies in the current AppDomain.

The name of the assembly passed in the assemblyName parameter should match that specified in the CodeModule element of the report definition file.

Examples

Legacy Code Example

In this example, a custom assembly containing a simple utility function that calculates factorials is used as an expression in a report.

using System.IO;
using System.Reflection;

public class Util
{
    public static int Factorial(int n)
    {
        return ((n <= 1) ? 1 : (n * Factorial(n - 1))); 
    }
}

The following code is used to add the custom assembly to the current AppDomain.

reportViewer.LocalReport.ReportPath = "Report1.rdlc";

reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Contoso.Utilities, 
      Version=1.0.271.0, Culture=neutral, PublicKeyToken=89012dab8080cc90");

For more information about custom assemblies, see "Using Custom Assemblies with Reports" in SQL Server Books Online.

See Also

LocalReport Class
Microsoft.Reporting.WinForms Namespace

Return to top