close

最近因修改與升級 Asp.Net的開發環境,在部署後,發現使用ReportViewer + RDLC 匯出 PDF檔 或者 Excel檔時
會有下列錯誤

完整的錯誤訊息如下,會因版本不同而有所差異

[A]Microsoft.Reporting.WebForms.ReportHierarchy cannot be cast to [B]Microsoft.Reporting.WebForms.ReportHierarchy. Type A originates from 'Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\12.0.0.0__89845dcd8080cc91\Microsoft.ReportViewer.WebForms.dll'. Type B originates from 'Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' in the context 'Default' at location 'C:\Windows\assembly\GAC_MSIL\Microsoft.ReportViewer.WebForms\11.0.0.0__89845dcd8080cc91\Microsoft.ReportViewer.WebForms.dll'.

 

意思就是說,不同版本的ReportViewer無法轉換
因為ReportViewer元件算是外部引用的原件,所以當使用到他的時候
會在Web.Config檔案裡面,增加下列的參考

<system.web>
    <httpHandlers>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" validate="false"/>
    </httpHandlers>
    <compilation debug="true" targetFramework="4.5">
      <assemblies>
        ............................
        <add assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        <add assembly="Microsoft.ReportViewer.Common, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845DCD8080CC91"/>
        ........................
      </assemblies>

.............

然後還有
<system.webServer>

  ................
    <handlers>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </handlers>
  </system.webServer>

.....

 

其實要注意的就是 版本問題
尤其是從.net 3.0 > 3.5 >4.0 >4.5 這樣一路升上來
有時候沒有此系去維護 Web.Config 檔,會發現他累積了不同版本的參考

有時候是在開發期就會出現,模稜參考,提醒你去修正他
最好還是注意一下,把所有使用到的元件都會成統一版本,在Web.Config的參考也保持著一個版本就好

不然有時執行起來還是會有些怪現象

arrow
arrow
    全站熱搜

    ADOLPH 發表在 痞客邦 留言(0) 人氣()