Rendering Flexreports in a Web API

Posted by: p.dellemann on 12 January 2022, 2:14 am EST

  • Posted 12 January 2022, 2:14 am EST

    Hello,

    We are currently in the process of updating all our software to either .Net 5.0 or 6.0 . During this process we have ran into an issue concering the rendering of reports in one of our APIs.

    We used to use the C1Report assembly to render with .RenderToStream and return a stream of the generated PDF file. We have since replaced this with the latest Flexreport package(C1.Win.FlexReport 5.0.20213.537) but the following line of code gives an exception:

    var report = new C1.Win.FlexReport.C1FlexReport();


    This gives the following exception:

    System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
    Could not load file or assembly 'System.Windows.Forms.Design, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Het systeem kan het opgegeven bestand niet vinden....


    The same issue is also happening when we make a test project in .Net 6.0 and add the same package and line of code there.

    It seems that this package requires several winforms assemblies which are not available in the WebAPI. Is there any other way for us to render? Have we missed a specific web package that might be used?
  • Marked as Answer

    Replied 13 January 2022, 2:58 am EST

    Hi,
    Please make sure that the targetted OS is set to windows for your Project. If not, please set it to true from the project properties.
    Then rebuild the project and check if it works or not.
    If not, please open the project file in edit mode and add the following line:
    <UseWindowsForms>true</UseWindowsForms>


    And save the updated project file and execute the project.

    Please share the demo project if the issue persists.

    Regards,
    Manish Gupta C1FlexReport_PrintPDF.zip
  • Replied 13 January 2022, 11:18 pm EST

    Setting that and switching from net5.0 to net5.0-windows managed to fix it.

    Thank you
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels