This is my code, trying to generate a crystal report in a class library project and return it as a stream, because I’m going to use this library in a .Net Core web API project.
public byte[] GenerateReport(string reportPath)
{
try
{
ReportDocument reportDocument = new ReportDocument(); //Error occures here
reportDocument.Load(reportPath);
using (MemoryStream stream = new MemoryStream())
{
reportDocument.ExportToStream(ExportFormatType.PortableDocFormat).CopyTo(stream);
return stream.ToArray();
}
}
catch (Exception ex)
{
// Handle exceptions here
throw new Exception($"Error generating report: {ex.Message}");
}
}
I’m getting the following error. Anyone to help with this issue?
I’m using visual studio 2022, Class library is targeting .net framework 4.7.2
FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.