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?
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