Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:31:25+00:00 2026-05-26T08:31:25+00:00

I need to automate some tasks in Adobe InDesign CS3 from a .NET 4.0

  • 0

I need to automate some tasks in Adobe InDesign CS3 from a .NET 4.0 application. I’ve added a reference to the InDesign Type Library using the Add Reference dialog in Visual Studio. It genereates an interop assembly, which correctly includes all of the interfaces and types declared in the type library. I haven’t installed any Adobe SDK, as the type library was available in Visual Studio without installing anything but Adobe InDesign CS3.

The interesting types in the interop assembly for me right now is the interfaces _Application and Application, and the class ApplicationClass. Here is the definition of them, so you can see the relationship between them:

public interface _Application
{
    // Lots of properties and methods
}

public interface Application : _Application
{
    // Empty
}

public class ApplicationClass : _Application, Application
{
    // The same properties and methods as declared in _Application
}

I try to instantiate the COM object like this:

Type oType = Type.GetTypeFromProgID("InDesign.Application.CS3");
if (oType != null)
{
    object instance = Activator.CreateInstance(oType);
}

This code succeeds. I get an instance, but of a type called __ComObject. From what I know, this is completely normal.

Now, here’s where the fun begins. For this instance to be usable to me, I should cast it to the correct interface. From other examples on the net, and from the documentation available here, I can see I should cast it to the Application interface. But if I do that, I get a nasty InvalidCastException saying that the type System.__ComObject doesn’t support this interface. I get the same exception if I try to cast it to ApplicationClass or the _Application interface.

I thought I was perhaps using an incorrect interface, so I tried implementing the utility function listed here. This function loops through all the interfaces declared in the interop assembly and queries the IUnknown interface if it implements the interface.

When I use that function, it returns null, meaning that the instance I get back from CreateInstance supports none of the interfaces in the interop assembly. Surely, that can’t be right!?

However, if I inspect the instance variable with the Visual Studio Debugger, there’s something called “Dynamic View”. If I expand that, it lists all the properties for the object and all the properties match the properties from the ApplicationClass class and the _Application interface. So I tried using Type.InvokeMember and that works:

oType.InvokeMember("DoScript", BindingFlags.InvokeMethod, null, instance, oArguments, CultureInfo.InvariantCulture);

This actually works, but it would be extremely cumbersome to interact with the COM object like this, and I need to do alot of interaction with the COM object, so this is not really usable. I guess I could make a wrapper for the COM objects, but that kind of defeats the purpose of the interop assembly, and I don’t want to create 700+ wrapper classes.

I’ve searched alot, and I’ve found tutorials and examples of using the InDesign COM object, but they all just cast the instance returned to the Application interface, but as explained, this doesn’t work in my case.

I’ve also tried the following code instead of the code above:

InDesign.Application app = new InDesign.Application();
app.Activate();

The first line succeeds and I get an instance of ApplicationClass, but when it tries to execute the second line I get a InvalidCastException stating that ApplicationClass cannot be converted to the interface _Application.

I’m really cornered up here, and not sure what to try next. I really hope someone more experienced with COM and .NET has an idea of what I could be doing wrong.

Thanks in advance, and sorry for such a long post.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:31:25+00:00Added an answer on May 26, 2026 at 8:31 am

    You have to use a Runtime Callable Wrapper

    The method you need is this one

    Try this :

        Type oType = Type.GetTypeFromProgID("InDesign.Application.CS3");
        if (oType != null)
        {
            object instance = Activator.CreateInstance(oType);// or any other way you can get it
            Application app = 
                (Application)System.Runtime.InteropServices.Marshal.CreateWrapperOfType(instance, typeof(ApplicationClass));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using WiPFlash to automate some testing in a WPF application. I need
I need to automate some tasks on a website that does not have an
I'm using Delphi 2010, and I need to run a console application and automate
I would like to automate some common tasks that I do using Visual Studio
I need to automate a process involving a website that is using a login
I'm looking to automate some web interactions, namely periodic download of files from a
I am using javamail to automate some email handling. I managed to get a
I need to automate a particular task that involves: Fetching mails from my mailbox
I'm writing some db utility scripts, and one of the tasks I need to
I'm working on a shell script to automate some server tasks. One the major

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.