C# LocalReport:如何从不同目录添加自定义代码

问题描述 投票:0回答:1

我在

Microsoft Reporting Services
应用程序中使用
.NET Framework 4.8
,使用
LocalReport
类来呈现 .rdlc 报告。

在我的报告中,我使用了一些附加程序集中的自定义代码,这些代码是通过“报告属性”->“引用”菜单添加到报告中的。

在我的代码中,当我渲染报表时,我添加了执行 LocalReport 域的程序集,以使它们在报表中可用,代码如下:

var assemblyName = myCustomAssembly.GetName();
var strongAssemblyName = new StrongName(new StrongNamePublicKeyBlob(assemblyName.GetPublicKeyToken()), assemblyName.Name, assemblyName.Version)
localReport.AddFullTrustModuleInSandboxAppDomain(strongAssemblyName);

现在,这工作得很好... 但前提是包含我尝试添加的程序集的 .DLL 与我的可执行文件位于同一文件夹中。如果它在其他地方(例如,在我的例子中,在子文件夹中),则报告生成失败,并出现异常,告诉我无法加载程序集,因为找不到 dll 文件。

有办法解决这个问题吗?我可以告诉 LocalReport 从特定文件夹加载程序集,或者以某种方式添加搜索路径吗?或者是将程序集放在我的应用程序的根文件夹中的唯一解决方案?

c# reporting-services reportviewer localreport
1个回答
0
投票

我会尝试设置 AppDomain 的基目录以包含您的子文件夹:

AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "path/to/your/subfolder");
AppDomain.CurrentDomain.SetData("BINPATH_PROBE_ONLY", "path/to/your/subfolder");
AppDomain.CurrentDomain.SetupInformation.PrivateBinPath = "path/to/your/subfolder";
© www.soinside.com 2019 - 2024. All rights reserved.