17 Replies Latest reply on Dec 17, 2015 2:02 PM by Trevorׅ

    C# Cannot handle the request because a modal dialog or alert is active

    michaelt5330502 Level 1

      I'm getting the error "Cannot handle the request because a modal dialog or alert is active" whenever I try to use the application object after its activation.

      This question has been asked multiple times, but it doesn't seem those solution could apply in my case....

      This error is occuring even before I open any InDesign document via code.


      Here's the InDesign part of the code, which I isolated and trying to get running.

              public static void ExportInDesignTest()
                  Type type = Type.GetTypeFromProgID("InDesign.Application");
                  Application application = (Application)Activator.CreateInstance(type);
                  application.ScriptPreferences.UserInteractionLevel = idUserInteractionLevels.idNeverInteract;
                  // Set unit type
                  application.ViewPreferences.HorizontalMeasurementUnits = idMeasurementUnits.idMillimeters;
                  application.ViewPreferences.VerticalMeasurementUnits = idMeasurementUnits.idMillimeters;


      The problem happens at line 7.

      I tried re-installing InDesign CS6, and re-referencing the COM files to my project, which didn't work.


      Can anyone lead me to some direction on how to fix this?



      Looking at the "application" object properties, I figured out that the issue probably comes from 15 Documents/Windows being opened in InDesign each time I activate/open it. Of those 15, some of them probably had modal dialog opened.
      The question now is how do I get rid of those documents permanently via script....I don't have InDesign running on the foreground, it's running on the background, so closing it via interface is out of the question, unless I can somehow move it to the foreground?
      Closing InDesign via task manager, and re-running the project doesn't work, and restarting also doesn't work. Very odd bug?