Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello everyone,

I am creating an application using reactjs as a frontend, asp.net 6.0 as a backend, I want to create report in crystal report and export this report to PDF and Excel using asp.net core web api.

I have written code in asp.net but some error in
ReportDocument reportDocument = new ReportDocument();

I am also sending error screenshot and code below..

Code is below :

ASP.NET
public async Task<iactionresult> GenerateReport()
{
    try
    {
        string rootDirectoryPath = _hostingEnvironment.ContentRootPath;
        string reportPath = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports" + "\\AccountReport.rpt");
        ReportDocument reportDocument = new ReportDocument();
        reportDocument.Load(reportPath);

        System.IO.MemoryStream stream = new System.IO.MemoryStream();
       
        stream.Seek(0, System.IO.SeekOrigin.Begin);
       
        return File(stream, "application/pdf", "report.pdf");
    }
    catch (Exception ex)
    {
        
        return StatusCode(500, $"Internal server error: {ex.Message}");
    }
}

Error is below :

FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
The system cannot find the file specified.

Please help me to solve this problem..

Thanks

What I have tried:

I have install all related Nuget Packges
Posted
Updated 19-Feb-24 5:59am
v2

1 solution

Solved: Crystal Reports for Visual Studio and .NET Core 5.... - SAP Community[^]

This thread suggests that Crystal Reports does not support .NET Core / .NET 5+; it only works in .NET Framework.

You will either need to rewrite your application in .NET Framework, or choose a different reporting tool.

You could try contacting SAP to see if they have any updated plans to support .NET, but at least one of the comments in that thread indicate that they're dropping all support for Visual Studio next year, so it's unlikely that their position has changed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900