Getting a Object Reference error in prod only when trying to use the Word DocumentClass

ⅰ亾dé卋堺 提交于 2019-11-30 20:29:04
user5390331
  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.

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

If word is really installed on the server check if the User account where IIS is running under has actually permission on the Microsoft.Office.Interop Assembly

After installing Office on the target machine, make sure you open one of the apps like Word directly because there may be more prompts for activating the license. The API won't work until you step through this process and the errors generated will not be clear as to what the problem really is.

The NullReferenceException may thus be caused by Word being unable to open the document, thereby Word.Documents.Open() would return null. To be honest I am not 100% sure this is what is causing your problem -- As I stated, the errors will not clearly tell you what the problem is. (I ran into this scenario myself a while ago and though I know the API was throwing an exception I cannot remember if it is the same as what you're seeing.)

Your program does not work locally in debug mode. You simply haven't exercised any of the bugs.

You should never, under any circumstances, use any of the Office Automation APIs from an ASP.NET application or any other server application. These APIs are designed as calls to an interactive, desktop application. Many of the assumptions they make do not apply to server applications.

For instance, a desktop application is synchronized by user actions becoming messages in the Windows message queue. There is no Windows message queue in your ASP.NET application, so access to shared data is not synchronized. Your tests may simply never have caused multiple threads to run at the same time.

There may be data that exists in only a single copy for all users of a given COM component. This works fine in a desktop application, since there is only a single user. Your ASP.NET application has many users all executing code at the same time. Another assumption violated.

All of these things will produce subtle bugs which cannot actually be fixed. They can only be moved around, leaving you to think you've solved the problem, right up to the time you realize that there's one more problem. This cycle never ends and never can end, because you will not have solved the actual problem: the problem was that you were using an Office Automation API from a server application.

Fix that problem, and you'll have no more bugs of this kind.


P.S. It also just so happens that you may be violating your license for Microsoft Word, unless all of the users of your ASP.NET application have licenses for the Word application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!