注意:此 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 _
)
[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
类型:String
要添加的程序集的名称。
备注
重要
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 <NetFx40_LegacySecurityPolicy> configuration element 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 代码访问安全策略兼容性和迁移.
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.
示例
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.