Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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.

Any ideas?

Microsoft.Office.Interop.Word.DocumentClass

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

lines of code:

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;
like image 514
RJ. Avatar asked Feb 25 '11 16:02

RJ.


People also ask

How to solve object reference not set to an instance of an object error?

To fix "Object reference not set to an instance of an object," you should try running Microsoft Visual Studio as an administrator. You can also try resetting the user data associated with your account or updating Microsoft Visual Studio to the latest version.

What does it mean object reference not set to an instance of an object?

The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs.


1 Answers

  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

like image 105
user5390331 Avatar answered Sep 30 '22 22:09

user5390331