繁体   English   中英

测试客户端上是否安装了Visual Studio 2010(及更高版本)的Crystal Reports

[英]Test if Crystal Reports for Visual Studio 2010 (and later) is installed on client

我继承了一个旧的Windows窗体应用程序(除其他外)是使用Crystal报表生成PDF:s进行打印。 我试图使其使用Crystal Reports for Visual Studio 2010组件的Crystal Reports for Visual Studio 2010而不是相同版本的旧版本,但是在检查客户端计算机上是否安装了所需的版本时遇到了问题。 我希望该应用程序即使没有安装Crystal也可以正常工作,当然要生成PDF。

该应用程序执行以下操作(不包括无关详细信息):

try {
    ReportDocument report = new ReportDocument();

    //do something with the report, produce pdf etc
}
catch(Exception e) {
    Log.Write(e);
    throw();
}

然后在调用表单中再次捕获该异常,该调用表单依次显示一些信息,包括下载正确的Crystal安装文件的链接。

我以为这以前是可行的,但是在我更新到Crystal组件13。#。#。#之后,这已经不够了。 ReportDocument report = new ReportDocument(); 触发System.TypeInitializationExceptionreport保留为null。 因此,我以后无法处理任何事情。 但是,创建了某些东西 ,因为过一会儿, Finalizer运行,导致引发另一个System.TypeInitializationException ,进而导致应用程序崩溃。

如何在运行new ReportDocument();之前测试是否已安装Crystal new ReportDocument(); 以某种方式不会导致终结器线程上的后续异常?

尝试使用反射加载类型。 这应该避免需要实例化,但是将允许您验证可以创建Type。

决定接受@PhillipH的回答,因为他指出了我的思考方向。 但是我仍然想展示我的实际工作。

我在ReportDocument report = new ReportDocument();上遇到的异常ReportDocument report = new ReportDocument(); 行说(除其他事项外):

Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.

因此,为了进行测试,我添加了以下内容:

            System.Reflection.Assembly a = System.Reflection.Assembly.ReflectionOnlyLoad("CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304");

在更新ReportDocument之前。 如果未安装Crystal,则会抛出该异常,调用表单将捕获该表单并显示“这里是如何下载和安装Crystal”表单。

免责声明 :我不习惯于使用Reflection因此我不能真正地说出这是好事还是完全愚蠢的事情。 似乎可以工作,但更改后没有Finalizer错误。

我只是检查组装路径:

If Not Directory.Exists(" C:\Windows\assembly\GAC_MSIL\CrystalDecisions.CrystalReports.Engine") Then
        InstallCrystalRuntime()
     End If

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM