「System.Runtime.InteropServices.COMException」類型的第一次機會異常在 System.Windows.Forms.dll 中發生

        最近作一個winform項目,在裏面用了webbrowser控件進行html文檔打印,遇到了標題所示問題。根據查到的一些資料,在調試》異常》查找中輸入「System.Runtime.InteropServices.COMException」,勾選查找到的項目後的複選框。從新調試程序,終於爆出了真正的問題:試圖吊銷一個未註冊的拖放目標 (異常來自 HRESULT:0x80040100 (DRAGDROP_E_NOTREGISTERED))。html

查看原來的代碼:web

1 browser.DocumentText = text; 2 browser.Print();

該段代碼作以下修改後問題解決:ide

1 browser.DocumentText = "";    // 不加這一句,Document對象可能爲null,致使下一句代碼出錯
2 browser.Document.Write(text); 3 browser.Print();
View Code
相關文章
相關標籤/搜索