仅在尝试使用Word DocumentClass时在prod中获取对象引用错误

RJ.*_*RJ. 6 .net c# asp.net ms-word office-automation

我正在编写一个使用.dotx模板的程序,并在aspx页面中进行数据合并.该程序在我的开发工作站本地工作正常,但当我将它部署到测试IIS服务器时,它在下面的第二行失败,给我一个对象引用错误.

我之前遇到问题,因为Word Com对象不在IIS服务器上,因此我将Word加载到服务器上并在DCom中设置权限并解决了该问题.但现在我在以wRange = .....开头的行上出现此错误

正如我所说,该程序在调试模式下完美地工作.

有任何想法吗?

Microsoft.Office.Interop.Word.DocumentClass

System.NullReferenceException: Object reference not set to an instance of an object
Run Code Online (Sandbox Code Playgroud)

代码行:

Document BaseDocument = oWord.Documents.Open(ref oTemplate, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

wRange = BaseDocument.Bookmarks.get_Item(ref endOfDoc).Range;
Run Code Online (Sandbox Code Playgroud)

小智 6

  1. 单击开始,单击程序,单击管理工具,单击组件服务。
  2. 依次展开组件服务、计算机、我的电脑、DCOM 配置,然后右键单击Microsoft Word 97 - 2003 文档。选择属性。
  3. 单击常规。将身份验证级别设置为连接(无也行)。
  4. 单击身份。设置此用户。指定将始终用于运行 COM 应用程序的用户帐户,无论哪个用户正在访问它。
  5. 单击按钮应用。
  6. 单击按钮确定。

有关“为远程访问配置 DCOM”的更多信息,请访问为远程访问配置 DCOM


fix*_*gon 0

如果服务器上确实安装了 word,请检查运行 IIS 的用户帐户是否确实具有 Microsoft.Office.Interop 程序集的权限