有
我有一个水晶报告问题:如果在客户环境中未安装水晶报表组件(无法找到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
中捕获异常答案 0 :(得分:0)
在部署应用程序时,应将CrystalDecisions.CrystalReports.Engine标记为“Copy Local”,以便将引用随应用程序一起安装。