Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

exception Object reference not set to an instance of an object sometimes

Community Beginner ,
Aug 15, 2011 Aug 15, 2011

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.


TOPICS
Scripting
992
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 15, 2011 Aug 15, 2011
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines