web-dev-qa-db-fra.com

Impossible de caster l'objet COM de type «CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass»

J'ai 2 programmes Windows.

Programme A: créer avec Visual Studio 2015 avec Crystal Report SP18

Programme B: créer avec Visual Studio 2017 avec Crystal Report SP22

J'ai un ordinateur avec l'exécution du rapport Crystal SP 18.

J'exécute le programme A sur cet ordinateur. Le programme A peut créer un rapport. J'exécute le programme B sur cet ordinateur. Le programme B ne peut pas créer de rapport. J'ai donc mis à niveau le runtime Crystal Report vers SP22. Le résultat est que le programme B peut créer un rapport.

Maintenant, le problème est que le programme A ne peut pas créer de rapport après la mise à niveau. L'erreur est:

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 '{98CDE168-C1BF-4179-BE4C-F2CFA7CB8398}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease)
   at CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Refresh()
   at CrystalDecisions.ReportSource.EromReportSourceBase.Refresh(RequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.FormatEngine.Refresh(RequestContext reqContext)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.Refresh()
   at CrystalDecisions.CrystalReports.Engine.Table.SetDataSource(Object val, Type type)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSourceInternal(Object val, Type type)
   at CrystalDecisions.CrystalReports.Engine.ReportDocument.SetDataSource(DataTable dataTable)
   at Portal_Inkaso.frIndex.PerintahCetakTT()
   at Portal_Inkaso.frIndex.Perintah1()
   at Portal_Inkaso.frIndex.llbPerintah_LinkClicked(Object sender, LinkLabelLinkClickedEventArgs e)
   at System.Windows.Forms.LinkLabel.OnLinkClicked(LinkLabelLinkClickedEventArgs e)
   at System.Windows.Forms.LinkLabel.OnMouseUp(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Label.WndProc(Message& m)
   at System.Windows.Forms.LinkLabel.WndProc(Message& msg)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Que devrais-je faire ? Rétrograder le temps d'exécution du rapport Crystal ou quoi?

10
Liudi Wijaya

Après avoir googlé longtemps, j'ai trouvé la solution.

La solution consiste à ajouter du code ci-dessous dans app.config/web.config

<runtime>
  <assemblyBinding xmlns="urn:schemas-Microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.CrystalReports.Engine" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportSource" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>    
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.Shared" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.Web" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.Windows.Forms" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.ClientDoc" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.CommonControls" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.CommonObjectModel" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.Controllers" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.CubeDefModel" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.DataDefModel" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.DataSetConversion" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>    
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.ObjectFactory" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.Prompting" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.ReportDefModel" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="CrystalDecisions.ReportAppServer.XmlSerialize" publicKeyToken="692fbea5521e1304" culture="neutral"/>
      <bindingRedirect oldVersion="13.0.2000.0" newVersion="13.0.3500.0"/>
    </dependentAssembly>
  </assemblyBinding>  
</runtime>

Ceci est la source Crystal Reports, Developer for Visual Studio Downloads

Solution

20
Liudi Wijaya

Supprimez simplement l'ancienne référence des rapports Crystal et ajoutez de nouveaux assemblages. cela est dû à la différence de version de Crystal Report, l'ancienne compilation fonctionnant avec les anciennes versions.

Ajoutez simplement un nouvel assemblage de référence de la version actuelle et une solution propre et reconstruisez le projet et exécutez.

Ça marche.