exception Object reference not set to an instance of an object sometimes
Copy link to clipboard
Copied
Sometimes, I get the following exception (most of the time, it doesn't happen).
for (int j = 1; j <= courseDocumentsCount; j++)
{
dynamic doc = app.Documents[1];
doc.Save(Utility.MergedFolder + "\\courses_" + j + ".indd");
doc.Close(idSaveOptions.idNo);
}
The exception is "Object reference not set to a instance of an object". It happens when I call doc.Save() and it happens because doc variable appears to be null.
Could this be some kind of "delay" in com intereop? In the previous iteration for the for loop, a document is closed and while Indesign is "in process of closing" the first document (the documents are large)....the code moves to the next iteration BUT opens the same index (since the original document is still closing, indesign returns the same reference). By the time it gets to the doc.Save() line, the original document has closed and the reference is now null. Could this be the issue?
This is Indesign Server btw. If this is the issue, how do I solve it? I noticed there is an app.WaitForAllTasks() but I don't think that's available in Server.
Copy link to clipboard
Copied
It's really a good idea for you to make it a lot more clear in your posts that you are using C# (or whatever it is). Because basically nobody else uses that and it looks far too similar to Javascript to be easily identifyable. So a lot of people get frustrated trying to help you. I know I do. Please help us help you.

