title: Why System.InvalidCastException in CrystalReport Export?
body: <p>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 <strong>System.InvalidCastException</strong> exception in this line? Also I am getting this exception in every Export function.</p>
  
  <pre><code>MemoryStream memoryStream = (MemoryStream)cryRpt.ExportToStream(ExportFormatType.PortableDocFormat);
  </code></pre>
  
  <p>Exception Details:</p>
  
  <blockquote>
    <p>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)).'</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/GMMzy.png" rel="nofollow noreferrer">Exception Screenshot</a></p>
  
  <p>Note: There is no problem with Crystal Report. When I use same code in a console application it works.</p>