WinForm客戶端軟件開發時,使用rdlc做報表,並且使用ReportViewer呈現報表時,開發者的機器運行正常。但是部署到第三方機器上運行時報錯。大致有以下幾種錯誤:
(1)未能加載文件或程序集“Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91”或它的某一個依賴項。系統找不到指定的文件。文件名:“Microsoft.ReportViewer.Common, Version=11.0.0.0, Culture=neutral,PublicKeyToken=89845dcd8080cc91”
(2)RDLC的部署(無法找到Microsoft.ReportViewer.ProcessingObjectModel.dll文件)
(3)找不到 Microsoft.SqlServer.Types.dll或者其他的依賴項
錯誤的提示意思是第三方機器上缺少相關dll。到程序開發計算機下找到對應的烤到客戶端的程序啟動目錄下即可(項目烤到Bin\\Debug目錄下)。由於以上的dll都是在開發者機器的Windows\assembly目錄中,
該目錄是微軟操作系統預定義的特殊目錄,無法直接操作里面的文件,只能通過命令來處理。
啟動cmd.exe程序,在窗口中輸入以下命令行,每次輸入一個命令,回車后復制成功。
copy C:\Windows\assembly\gac_msil\Microsoft.ReportViewer.Common\11.0.0.0__89845dcd8080cc91\Microsoft.ReportViewer.Common.dll D:\ReportViewer
copy C:\Windows\assembly\gac_msil\Microsoft.ReportViewer.WinForms\11.0.0.0__89845dcd8080cc91\Microsoft.ReportViewer.WinForms.DLL D:\ReportViewer
copy C:\Windows\assembly\gac_msil\Microsoft.ReportViewer.ProcessingObjectModel\11.0.0.0__89845dcd8080cc91\Microsoft.ReportViewer.ProcessingObjectModel.DLL D:\ReportViewer
copy C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0__89845dcd8080cc91\Microsoft.SqlServer.Types.dll D:\ReportViewer
【其他的dll復制方式與此類似】
復制到D盤ReportViewer目錄后,將其復制到項目的bin\Debug目錄,再次運行程序,一切正常。