无法捕获Crystal报表异常

时间:2015-07-26 05:08:51

标签: c# exception crystal-reports

我有一个水晶报告问题:如果在客户环境中未安装水晶报表组件(无法找到CrystalDecisions.CrystalReports.Engine.dll),则异常无法在代码段1中捕获,但可以在代码段中捕获2

代码段1:

    private void button1_Click(object sender, EventArgs e)
    {
            try
            {
                var rtDocument = new ReportDocument();
            }
            catch (Exception)
            {
              //The exception cannot be caught if Crystal report environment is broken or not installed.
                Console.WriteLine("Exception......");
            } 
    }

代码段2:

public class ReportDialog:Form
{
    public ReportDialog()
    {
        var a = new ReportDocument();
        Console.WriteLine("ReportDocument OK");
    }
}
    private void button1_Click(object sender, EventArgs e)
    {
            try
            {
                var d = new ReportDialog();
            }
            catch (Exception)
            {
              //The exception can be caught if crystal report component is broken or not installed

                Console.WriteLine("Exception......");
            } 
    }

问题是:我想知道如何在代码片段1

中捕获异常

1 个答案:

答案 0 :(得分:0)

在部署应用程序时,应将CrystalDecisions.CrystalReports.Engine标记为“Copy Local”,以便将引用随应用程序一起安装。