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.

asked on Stack Overflow Sep 5, 2018 by Md. Rasedur Rahman Roxy • edited Sep 5, 2018 by Alex K.

2 Answers


Because it does not return a MemoryStream.

Take a look at this link to get more information. They say that method returns an instance of FileStreamDeleteOnClose since some version of Crystal and it was a decision of the developers.

Take a look at this post to see how to approach it in another way.


In this post, the workaround was to downgrade Crystal Reports. Not nice...

In SAP forums, there is a discussion about it. It is said that, to avoid that, Microsoft Windows Update KB2999226 is a prerequisite for SP21 (among some details). Check your Crystal Reports version and check if it applies to you.

answered on Stack Overflow Sep 5, 2018 by heringer • edited Sep 6, 2018 by heringer

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.

User contributions licensed under CC BY-SA 3.0