仅在尝试使用 Word DocumentClass 时在 prod 中出现对象引用错误 [英] Getting a Object Reference error in prod only when trying to use the Word DocumentClass

查看:23
本文介绍了仅在尝试使用 Word DocumentClass 时在 prod 中出现对象引用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a program that uses a .dotx template and does a merge of data in an aspx page. The program works perfect on my Dev workstation locally but when I deploy it to a test IIS server, it fails on the second line below giving me an Object Reference error.

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

I ran into problems earlier because the Word Com object was not on the IIS server so I loaded Word onto the server and set permission in DCom and got past that problem. But now I get this error on the line that starts with wRange = .....

正如我所说,该程序在调试模式下可以在本地完美运行.

As I said, the program works perfectly locally in debug mode.

有什么想法吗?

Microsoft.Office.Interop.Word.DocumentClass

System.NullReferenceException: Object reference not set to an instance of an object

代码行:

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;

推荐答案

  1. 依次单击开始"、程序"、管理工具"和组件服务".
  2. 展开组件服务、展开计算机、展开我的电脑、展开 DCOM 配置,然后右键单击 Microsoft Word 97 - 2003 文档.选择属性.
  3. 单击常规.将身份验证级别设置为连接"(也没有).
  4. 点击身份.设置此用户.指定将始终用于运行 COM 应用程序的用户帐户,无论哪个用户正在访问它.
  5. 点击按钮应用.
  6. 单击确定"按钮.
  1. Click Start, click Programs, click Administrative Tools, click Component Services.
  2. Expand Component Services, expand Computers, expand My Computer, expand DCOM Config, and right-click Microsoft Word 97 - 2003 Document. Select Properties.
  3. Click General. Set Authentication Level to Connect (None also work).
  4. Click Identity. Set This user. Specify a user account that will always be used to run the COM application regardless of which user is accessing it.
  5. Click button Apply.
  6. Click button OK.

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

For more information on "Configuring DCOM for Remote Access" visit Configuring DCOM for Remote Access

这篇关于仅在尝试使用 Word DocumentClass 时在 prod 中出现对象引用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆