I have tried generating a PDF directly from my report and I have tried opening it in a viewer. I always come back to this error.
FileNotFoundException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I've tried installing the package listed in Nuget, but that exact version does not appear to be available. The versions I tried did not fix the problem.
Here is my code for generating the report...
InstanceReportSource report = new InstanceReportSource();
report.ReportDocument = new BatchReport();
report.Parameters.Add("BatchNumber", batch.ID);
ReportGenerator.DisplayPDF(report);
public static void DisplayPDF(InstanceReportSource source)
{
ReportProcessor reportProcessor = new ReportProcessor();
RenderingResult result = reportProcessor.RenderReport("PDF", source, null);
if (!result.HasErrors)
{
string fileName = result.DocumentName + "." + result.Extension;
string path = System.IO.Path.GetTempPath();
string filePath = System.IO.Path.Combine(path, fileName);
using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
{
fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
}
Process.Start($"file://{filePath}");
}
}
BTW, I am working on a .NET Framework 4.7.2 project.
The exception I posted above is the INNER exception. The outer one is this...
System.TypeInitializationException: 'The type initializer for 'Telerik.Reporting.OpenXmlRendering.Wordprocessing.WordprocessingReport' threw an exception.'