5 Replies Latest reply on Feb 10, 2014 9:48 AM by claudio_pais

    doc.AllGraphics crash in C#.

    AdobeInDesignScriptKiddie

      InDesign.Document doc = (InDesign.Document)app.Open(PathToInDesignFile, true); // works fine

      InDesign.Graphics allGraphics = (InDesign.Graphics)doc.AllGraphics; // crashes with an exception

       

      That's the exception:

      Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Graphics'.

      This operation failed because the QueryInterface call on the COM component for the interface with IID '{C85A4AB§-9492-...}' failed due to the following error:

      No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

       

      How to solve this problem?

        • 1. Re: doc.AllGraphics crash in C#.
          MrTIFF Level 3

          Well, I'm a JavaScript guy, but the object reference says that Document.allGraphics returns an Array, not a 'Graphics' object.

          • 2. Re: doc.AllGraphics crash in C#.
            AdobeInDesignScriptKiddie Level 1

            I've rewritten the Code to make it more clearly. The code now uses Graphic instead Graphics.

            Basically I get the same Exception, as I get:

            "Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Graphic'...

            Previously I got:

            Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Graphics'.

             

            int iCount = doc.AllGraphics.Count; // iCount is 1

            for (int i = 1; i <= doc.AllGraphics.Count; i++) // works

            {

                 InDesign.Graphic graphic = (InDesign.Graphic)doc.AllGraphics[i]; // crash! Exception!

            }

             

            So, anyone any ideas how to solve the problem?

            • 3. Re: doc.AllGraphics crash in C#.
              MrTIFF Level 3

              Well, aren't Arrays zero-based in C#?

              And you shouldn't need the cast at all.

              And I think Length is more standard than Count for the size of an Array ...

              • 4. Re: doc.AllGraphics crash in C#.
                AdobeInDesignScriptKiddie Level 1

                > And you shouldn't need the cast at all.

                I guess in the context of official InDesign scripting (Javascript, VBScript, Applescript) you are right.

                But I use ".Net C#" an the com-InDesign-Lib, so if I don't cast, then "doc.AllGraphics[i]" is just an object, and you could only use the following 4 methods:

                doc.AllGraphics[i].Equals

                doc.AllGraphics[i].GetHashCode

                doc.AllGraphics[i].GetType

                doc.AllGraphics[i].ToString

                 

                > Well, aren't Arrays zero-based in C#?

                That's the case in the context of classical NET-Programming.

                However in the context of .NET-C# InDesign-Com-Programming, arrays start with the index 1.

                If you use zero-based index then the exception "The requested member of the collection does not exist" appears:

                int iCount = doc.AllGraphics.Count; // iCount is 1

                for (int i = 0; i < doc.AllGraphics.Count; i++)

                {            

                InDesign.Graphic graphic = (InDesign.Graphic)doc.AllGraphics[i]; // crash! (Value of "i" is "0" when it crashes here) Exception: The requested member of the collection does not exist

                }

                 

                Arn't there any Net-Programmers getting the same exception "Unable to cast COM object of type 'System.__ComObject' to interface type 'InDesign.Graphics'"?

                • 5. Re: doc.AllGraphics crash in C#.
                  claudio_pais

                  I have the same problem. Did you found any solution?