Search code examples
c#wcfcrystal-reports

Why System.InvalidCastException in CrystalReport Export?


I am creating a WCF service which will create .pdf using Crystal Report and save the file in specific path in server. Why I am getting System.InvalidCastException exception in this line? Also I am getting this exception in every Export function.

MemoryStream memoryStream = (MemoryStream)cryRpt.ExportToStream(ExportFormatType.PortableDocFormat);

Exception Details:

System.InvalidCastException: 'Unable to cast COM object of type 'CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass' to interface type 'CrystalDecisions.ReportAppServer.Controllers.ISCRReportSource'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{31E7715A-8AD0-4D1C-958E-C1BE0A6F2D0C}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).'

Exception Screenshot

Note: There is no problem with Crystal Report. When I use same code in a console application it works.


Solution

  • OK. My problem is solved by just updating the Crystal Report to Version 18.0.23. May be older version doesn't work well with WCF.