轉載於https://blog.csdn.net/songjuntao8/article/details/98096194 留作記錄方便查找。
用vs2017寫的一個winform程序用到水晶報表,水晶報表自己安裝好后,做出來的程序打印功能沒問題,在用戶的電腦上裝好后打印功能怎么都不能用,點擊就出現這個問題“CrystalDecisions.CrystalReports.Engine.ReportDocument的類型初始值設定項已發異常 ”
System.TypeInitializationException: “CrystalDecisions.CrystalReports.Engine.ReportDocument”的類型初始值設定項引發異常。 ---> System.Runtime.InteropServices.COMException: 檢索 COM 類工廠中 CLSID 為 {4DB2E2BB-78E6-4AEA-BEFB-FDAAB610FD1B} 的組件失敗,原因是出現以下錯誤: 80040154 沒有注冊類 (異常來自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
在 CrystalDecisions.CrystalReports.Engine.ReportDocument..cctor()
--- 內部異常堆棧跟蹤的結尾 ---
在 CrystalDecisions.CrystalReports.Engine.ReportDocument..ctor()
在 CrystalDecisions.CrystalReports.Engine.ReportClass..ctor()
在 Cstm_Order_Fee_Manage.CrystalReport6..ctor() 位置 F:\Work\Logistic_net\Cstm_Order_Fee_Manage\CrystalReport6.vb:行號 25
在 Cstm_Order_Fee_Manage.frm_PrintTest..ctor() 位置 F:\Work\Logistic_net\Cstm_Order_Fee_Manage\frm_PrintTest.vb:行號 3
在 Cstm_Order_Fee_Manage.Frm_Cstm_Order_Fee.Button1_Click(Object sender, EventArgs e) 位置 F:\Work\Logistic_net\Cstm_Order_Fee_Manage\Frm_Cstm_Order_Fee.vb:行號 3707
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
根據程序提示的以為是COM組建沒注冊導致了,根據注冊表提示的注冊之后提示的就更奇怪了
************** 異常文本 **************
System.Runtime.InteropServices.COMException (0x80040154): 從 IClassFactory 為 CLSID 為 {F734A321-8381-4FFD-A614-139E8906DC83} 的 COM 組件創建實例失敗,原因是出現以下錯誤: 80040154 沒有注冊類 (異常來自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))。
在 CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.CreateRptDoc()
在 CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper..ctor()
在 CrystalDecisions.CrystalReports.Engine.ReportDocument.Initialize()
在 CrystalDecisions.CrystalReports.Engine.ReportDocument..ctor()
在 CrystalDecisions.CrystalReports.Engine.ReportClass..ctor()
在 Cstm_Order_Fee_Manage.CrystalReport5..ctor() 位置 F:\Work\Logistic_net\Cstm_Order_Fee_Manage\CrystalReport5.vb:行號 25
在 Cstm_Order_Fee_Manage.frm_Test..ctor() 位置 F:\Work\Logistic_net\Cstm_Order_Fee_Manage\frm_Test.vb:行號 2
在 Cstm_Order_Fee_Manage.Frm_Cstm_Order_Fee.Button1_Click(Object sender, EventArgs e) 位置 F:\Work\Logistic_net\Cstm_Order_Fee_Manage\Frm_Cstm_Order_Fee.vb:行號 3708
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
前后花了好幾天實在找不見原因。最后建的空的打印報表測試,空的在客戶機是可以,同樣的方法加在運行的程序就是不行。
裝了很多個版本的水晶報表運行時都不行。最后SAP官網的這個帖子幫了大忙
原因就是出在運行時了,開發端用的是CRRedist2008版本的水晶報表,使用高版本的運行時就可以了。希望能幫到大家。
登陸此網站進行下載 :http://www.ziyuanduoduo.cn/
CRRuntime_32bit_13_0_25.msi (32為SP25 截止2019.8.1 最新的客戶端運行時)
CRRuntime_64bit_13_0_25.msi (64為SP25 截止2019.8.1 最新的客戶端運行時)
希望能幫到大家。
————————————————
版權聲明:本文為CSDN博主「宋軍濤」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/songjuntao8/article/details/98096194