Accessing Attributes on Components of Subassemblies

I'm creating an addin in C#. In the ConnectToSW() method, I create an attribute definition:

private ISldWorks swApp;

private AttributeDef testAttrDef;

public bool ConnectToSW(object ThisSw, int cookie) {

  this.swApp = (ISldWorks)ThisSw;

  /* snip */

  // create an attribute definition for testing

  this.testAttrDef = this.swApp.IDefineAttribute("Test Attribute Definition");

  this.testAttrDef.AddParameter("Test Parameter 1", (int)swParamType_e.swParamTypeString, 0.0, 0);

  this.testAttrDef.Register();

  /* snip */

}

Then, I setup a model with one part, one (sub)assembly, and one assembly, where (when viewed from the top level) the components are MyAssembly, MyAssembly/MySubassembly, MyAssembly/MySubassembly/MyPart. With the model document of MySubassembly open, I selected the MyPart component and created an instance of my test attribute on it:

public void AssignAttribute() {

  ModelDoc2 currentDoc = this.swApp.IActiveDoc2;

  ISelectionMgr selectMgr = currentDoc.ISelectionManager;

  if (selectMgr.GetSelectedObjectCount2(-1) != 0) {

    Object selection = selectMgr.GetSelectedObject6(1, -1);

    if ((selection as Component2) != null)

      this.testAttrDef.CreateInstance5(currentDoc,

                                       selection,

                                       "Test Attribute Instance",

                                       0,

                                       (int)swInConfigurationOpts_e.swAllConfiguration);

  }

}

Finally, I opened the top-level assembly (MyAssembly), and call the following function (passing the arguments null and false to it):

public void DisplayAttributes(Feature firstFeature, bool isSubFeature) {

  Feature currentFeature;

  if (firstFeature == null)

    currentFeature = this.swApp.IActiveDoc2.IFirstFeature();

  else

    currentFeature = firstFeature;

  while (currentFeature != null) {

    Object specificFeature = currentFeature.GetSpecificFeature2();


    if ((specificFeature as Component2) != null) {

      Component2 comp = specificFeature as Component2;

      SolidWorks.Interop.sldworks.Attribute attr;


      for (int i = 0; (attr = comp.IFindAttribute(this.testAttrDef, i)) != null; i++)

        System.Windows.Forms.MessageBox.Show(comp.Name2 + " has attribute " + attr.GetName());

    }

    Feature subFeature = currentFeature.IGetFirstSubFeature();

    if (subFeature != null)

      this.DisplayAttributes(subFeature, true);

    if ((specificFeature as Component2) != null)

      this.DisplayAttributes((specificFeature as Component2).FirstFeature(), false);

    if (!isSubFeature)

      currentFeature = currentFeature.IGetNextFeature();

    else

      currentFeature = currentFeature.IGetNextSubFeature();

  }

}

The problem is, Component2.IFindAttribute() never returns the attribute I instantiated (always null), unless the active document is the same as the one in which the attribute was instantiated. Worse, when I get the attribute's feature in the feature tree (by recursively traversing it), call Feature.GetSpecificFeature2() on it to get the Attribute object, and call Attribute.IGetComponent2() on that object, it also returns null. More bewildering is the fact that this behaviour differs from that of attributes instantiated on Body2s (bodies) and Entitys (faces, edges, and vertices), in that calls to FindAttribute() on them return all of the attributes instantiated on them, irrespective of the model document in which they were instantiated. Am I missing something? How do I determine which attributes have been instantiated on a component when it is not directly subordinate to the root component of the active document?

SolidworksApi macros