"Object has been deleted" error on earlier worked Word add-in

ApsSanj 6 Reputation points
2026-09-29T09:16:01.0166667+00:00

I've been maintaining a project (VSTO Word add-in) and it has been working fine for years. Now for some users, it is giving "System.Runtime.InteropServices.COMException HRESULT 0x800A16C1 Object has been deleted" error in certain scenarios. No recent changes to the code done in that area recently. The issue is not recreating in my machine, and for those users, it is not recreating every time. Once they got the error once on a document in a single Word application object, then the error began to appear on all Word documents open user the same application object.

There are several places where we identified as the error is generating.

  1. Creating a temporary document copy of the active document. After the this.wordDocument.Save() is triggered, in the next line, when try to access the this.wordDocument.FullName , it throws the "Object has been deleted" error.
//If this document has a file name,
if (this.wordDocument.Path.Length > 0)
{
	//create a new document using this document as a template.
	this.wordDocument.Save();
	copy = tools.GetDocument(tools.WordApp.Documents.Add(Template: this.wordDocument.FullName, Visible: visible));  <-
}
  1. Download Word documents from our server, and open it in Word. In here, we do several updates to the document content within the Application_DocumentOpen event. The document is having few document variables, lots of field tags, we do some updates to the document variables, refresh the field code content(when necessary) and then do a programmatic Save. We are adding some logs in the process for troubleshooting and logs are kind of weird.
//In ServerFile.cs, document open action calls in here

//...more code here
//Download the document
//Open the document. Add log line "Attempting to open the document"

wordDocument = wordApp.Documents.Open(fileName, ReadOnly: false);
if(wordDocument != null)
{
	//Add log "Document opened in Word"
}

Then it executes the ThisAddIn.Application_DocumentOpen and runs the Tools.DocumentOpen code.

//This goes inside the Tools.DocumentOpen code
if (IsDocumentProtected(objDoc, "DocumentOpen") == false)  
{      	
	objDoc.UpdateTagsIfBroken();      //logs related to UpdateTagsIfBroken, access oDocument.WordDocument.Fields within this.
	objDoc.RemoveFlagsIfNotCheckedOut();  //logs related to RemoveFlagsIfNotCheckout
	bool isChange = !objDoc.WordDocument.Saved;      		
	if (isChange)	
	{          		
		this.ReqDocumentSave = true;      	
	} 
}
//This goes in the ThisAddIn.cs class
public void Application_DocumentOpen(Word.Document doc)
{
	ABC.Application app = new ABC.Application();	
	app.Tools.DocumentOpen(doc);
				
	if (app.Tools.ReqDocumentSave) 	
	{		
		isDocumentSaveWhenOpen = true;		
		doc.Save();	
	}
}

The log should be like below.

Attempting to open the document
logs related to UpdateTagsIfBroken
logs related to RemoveFlagsIfNotCheckout
Document opened in Word

But it is like below when the error occurs.

Attempting to open the document
logs related to UpdateTagsIfBroken
logs related to RemoveFlagsIfNotCheckout
Error System.Runtime.InteropServices.COMException HRESULT 0x800A16C1 throws when accessing oDocument.WordDocument.Fields
Document opened in Word

The error line is occurring out of the normal steps. The oDocument.WordDocument.Fields executes within the UpdateTagsIfBroken function which should not execute again within this flow. But somehow it is executing. So, I feel like the DocumentOpen event is triggering again. I am not sure though.
Cannot add more logs and check as I don't recreate the issue and cannot bother the user always with test installers.

Important points about the error

  • Both identified issue generating places are having this error after a programmatic document save.
  • User is downloading the document into a One-Drive shared local location.
  • User claims they have 'auto save' off.
  • User is having Microsoft Office version 2607
  • As it started to happen recently, it should be due to some change in Word.
  • Apart from the customer who reported the error, we have another error report from other user of the same error.

As a fix, I tried reacquiring the wordDocument object by using a cached document name when this error occurred. But for the error that occurs during the DocumentOpen event, it is kind of tricky. And I don't know if it is the right way to fix this.

Please help me with figuring out what is happening and how to fix it.

Thank you.

Regards,
Apsara

Microsoft 365 and Office | Word | Other | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Kai-H 28,425 Reputation points Microsoft External Staff Moderator
    2026-09-30T09:50:35.4133333+00:00

    Hi, ApsSanj

    The common clue is that the exception appears around a programmatic save, but I would not conclude from the logs alone that DocumentOpen fired a second time. DocumentOpen runs when a document opens; Word also has a separate DocumentBeforeSave event that runs before an open document is saved. A call made from a save-related handler, or another callback in your add-in, could account for the later UpdateTagsIfBroken() log entry. That is something to verify, not yet a confirmed diagnosis.

    Here are some suggestions you can try:

    Capture the path before saving in the copy routine. Read this.wordDocument.FullName before this.wordDocument.Save(), rather than making the next line depend on the same document reference still being usable. If Save() throws, or a subsequent access to the document fails, stop that operation instead of continuing with the cached object. A cached path can help you identify the document, but it does not make an invalid document reference valid again.

    Trace every route into UpdateTagsIfBroken(), not just DocumentOpen. In particular, check your save-related handlers and any callbacks they invoke. Log entry and exit for Application_DocumentOpen, UpdateTagsIfBroken(), and each programmatic Save(), along with a per-operation ID and the document path captured before saving. That should tell you whether this is a second open event, a nested call during the first one, or a separate call after it. Word’s documented save event makes that distinction worth checking.

    Guard the save inside Application_DocumentOpen. If your own save-related code can call back into document-processing code, use a per-document “save in progress” guard so it does not process that same document again while your doc.Save() is running. Clear the guard in a finally block. I would avoid a single application-wide flag unless you intend it to suppress processing for every open document.

    Test the file location separately from the code path. On an affected machine, try the same document and add-in workflow from a non-synced local folder, then from the OneDrive-synced folder. Keep the Word build the same for that comparison. OneDrive-synced Office files have their own collaboration integration, but the location alone does not establish that synchronization caused this exception, and turning AutoSave off does not settle the question.

    Reacquiring the document may be reasonable after you confirm that the original reference is no longer usable and identify the correct document. I would not make reacquisition by name the primary fix yet, especially with multiple documents open. First determine which call runs after the save and whether it is using a reference retained from an earlier step. I also would not label this a Word 2607 regression without a comparison against another build using the same file and workflow.

    Was this answer helpful?

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.