注意:此 API 现在已过时。
将提供的程序集添加至可以在当前 AppDomain 中执行的程序集列表。
命名空间:  Microsoft.Reporting.WinForms
程序集:  Microsoft.ReportViewer.WinForms(在 Microsoft.ReportViewer.WinForms.dll 中)
语法
声明
<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 _
)
用法
Dim instance As LocalReport
Dim assemblyName As String
instance.AddTrustedCodeModuleInCurrentAppDomain(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.")]
public void AddTrustedCodeModuleInCurrentAppDomain(
    string assemblyName
)
[ObsoleteAttribute(L"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
)
[<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 
public function AddTrustedCodeModuleInCurrentAppDomain(
    assemblyName : String
)
参数
- assemblyName
 类型:System.String
 要添加的程序集的名称。
注释
| .gif) 重要提示 | 
|---|
| 此方法已在 .NET Framework 4 中被否决,因为在 .NET Framework 4 中否决了此方法依赖的代码访问安全性 (CAS) 功能。ReportViewer 控件改为始终在沙盒应用程序域中执行。您应当使用 AddFullTrustModuleInSandboxAppDomain 和 SetBasePermissionsForSandboxAppDomain。如果要继续将此方法用于 .NET Framework 4.0,则必须在 ASP.NET 应用程序的 Web.config 文件中使用 <NetFx40_LegacySecurityPolicy> 配置元素。否则,此方法将引发 InvalidOperationException。 此方法将继续用于 .NET Framework 3.5。 有关更多信息,请参见Code Access Security Policy Compatibility and Migration。 | 
报表中的表达式将在仅带有 Execution 安全权限标志的当前 AppDomain 中执行。默认情况下,不允许在此模式下使用自定义程序集。AddTrustedCodeModuleInCurrentAppDomain 方法可用于允许在当前 AppDomain 中使用自定义程序集。
在 assemblyName 参数中传递的程序集的名称应该与在报表定义文件的 CodeModule 元素中指定的名称匹配。
示例
在此示例中,将包含用于计算阶乘的简单实用工具函数的自定义程序集用作报表中的表达式。
using System.IO;
using System.Reflection;
public class Util
{
    public static int Factorial(int n)
    {
        return ((n <= 1) ? 1 : (n * Factorial(n - 1))); 
    }
}
下面的代码用于将自定义程序集添加至当前 AppDomain。
reportViewer.LocalReport.ReportPath = "Report1.rdlc";
reportViewer.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Contoso.Utilities, 
      Version=1.0.271.0, Culture=neutral, PublicKeyToken=89012dab8080cc90");
有关自定义程序集的更多信息,请参见 SQL Server 联机丛书中的“在报表中使用自定义程序集”。