【问题标题】:Weird Error. 8007007E : Retrieving the COM class factory for component{} - 8007007E奇怪的错误。 8007007E:检索组件的 COM 类工厂{} - 8007007E
【发布时间】:2016-01-08 11:28:37
【问题描述】:

我在 Windows 2003 Server 32 位操作系统上部署了一个 Web 应用程序(在 VS 2008 中开发)。 我的应用程序使用 Microsoft Office Word(我正在使用它来生成 PDF)。 应用程序运行良好,正在生成 .Doc 和 .Pdf。 但是,一旦我重新启动服务器,我只会第一次收到上述错误 (8007007E),在我刷新页面后,应用程序再次开始正常工作。 我查找了错误的各种原因,但没有一个与我的匹配。 通常,当此错误发生时,它会导致 COM 使用完全崩溃。 代码示例如下。

string htmlContent = div_Data.InnerHtml;
string filename = strLoanNo + strTime + ".doc";
if (!Directory.Exists(Server.MapPath("~/Doc/")))
{
 Directory.CreateDirectory(Server.MapPath("~/Doc/"));
}
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
div_Data.RenderControl(hw);
FileStream fs = new FileStream(Server.MapPath("~/Doc/") + filename,FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.Write(tw.ToString());
sw.Flush();
sw.Close();
fs.Close();

object fileName = Server.MapPath("~/Doc/") + filename;
object missing = System.Reflection.Missing.Value;
object readOnly = false;
object isVisible = true;
object SaveChanges = true;
Microsoft.Office.Interop.Word.ApplicationClass appWord = new Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document oWordDoc = appWord.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing, ref missing);
oWordDoc.ExportAsFixedFormat(Server.MapPath("~/Doc/") + strLoanNo + "_" + strTime + ".pdf", WdExportFormat.wdExportFormatPDF, false, WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 1, 1, WdExportItem.wdExportDocumentWithMarkup, true, false, WdExportCreateBookmarks.wdExportCreateNoBookmarks, false, true, true, ref missing);
((_Document)oWordDoc).Close(ref SaveChanges, ref missing, ref missing);
 appWord.Quit(ref SaveChanges, ref missing, ref missing);
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(appWord);

Response.Clear();
Response.Charset = "";
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=" + strLoanNo + "_" + strTime + ".pdf");
        Response.WriteFile(Server.MapPath("~/Doc/") + strLoanNo + "_" + strTime + ".pdf");
Response.Flush();
Response.Close();

if (File.Exists(Server.MapPath("~/Doc/") + strLoanNo + strTime + ".doc"))
{
  File.Delete(Server.MapPath("~/Doc/") + strLoanNo + strTime + ".doc");
}
if (File.Exists(Server.MapPath("~/Doc/") + strLoanNo + strTime + ".pdf"))
{
  File.Delete(Server.MapPath("~/Doc/") + strLoanNo + strTime + ".pdf");
}

【问题讨论】:

    标签: asp.net windows iis-6 com+ dcom


    【解决方案1】:

    目前不确定代码是否重要,因为问题可能出在某处的 DLL 上,但是只有系统管理员才能告诉您哪一个在苦苦挣扎。如果可以,请使用进程监视器来隔离出现故障的组件https://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

    谢谢, 顶点

    【讨论】:

    • 如果是 DLL 问题,它不会一次又一次地报错吗?
    • 我可能是错的,但我很确定只要创建相应的 COM 对象,COM DLLS 就会按需加载(显然这并不意味着您的 COM DLL 有问题,它可能是任何 DLL)。所以听起来初始加载和DLL加载之间存在延迟,只是一个理论,我仍然认为你应该隔离。希望对您有所帮助。
    • 我认为 DLL 的按需加载理论似乎相当准确,因为无论我在重启后等待多长时间,第一个实例总是会引发错误。将 Doc 转换为 Pdf 我确实安装了一些附加的 Microsoft 插件...可能是它们没有与 COM 服务一起启动
    猜你喜欢
    • 1970-01-01
    • 2016-06-28
    • 2012-08-05
    • 1970-01-01
    • 2015-08-01
    • 2012-04-25
    相关资源
    最近更新 更多