4

I am trying to work with COM+ using c# and ASP.NET. I have been following an example, however part of it fails.

dynamic oCatalog = Activator.CreateInstance(Type.GetTypeFromProgID("ComAdmin.COMAdminCatalog"));
/* Get the Applications collection and populate it */
dynamic applicationInstances = oCatalog.GetCollection("Applications");
applicationInstances.Populate();
foreach (dynamic applicationInstance in applicationInstances)
    {
        Response.Write("<p>" + applicationInstance.Name.ToString() + "-" + applicationInstance.Key.ToString() + "</p>");
        dynamic objComponents = oCatalog.GetCollection("Components", applicationInstance.Key);
        objComponents.Populate();
        foreach(dynamic Components in objComponents)
        {
            Response.Write("<p>" + Components.Name.ToString() + "</p>");
        }           
    }

When the above call oCatalog.GetCollection("Components", applicationInstance.Key) is called I get the error:

System.Reflection.TargetParameterCountException: Error while invoking GetCollection.

How can I get a list of the current components in an application instance?

1 Answer 1

8

You need to ask the "applications" collection for the components for an specific application:

ICOMAdminCatalog2 oCatalog = (ICOMAdminCatalog2) Activator.CreateInstance(Type.GetTypeFromProgID("ComAdmin.COMAdminCatalog"));

ICatalogCollection applications = oCatalog.GetCollection("Applications");
applications.Populate();
foreach (ICatalogObject applicationInstance in applications)
{
    ICatalogCollection comps = applications.GetCollection("Components", applicationInstance.Key);
    comps.Populate();
    foreach (ICatalogObject comp in comps)
    {
        Console.WriteLine("{0} - {1}", comp.Name, comp.Key);
    }
}

for an example check here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686093(v=vs.85).aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.