GetObjectByPersistReference3 fails for ref I just got (in Assembly)

The following code throws my exception when run from an Assembly.

Why does the ModelDoc2 not accept a persistreference3 that it just handed me?

        const int PERSIST_REF_OBJ_OK = (int)swPersistReferencedObjectStates_e.swPersistReferencedObject_Ok;

        public List SegmentsToPersistRefs(List segments)

        {

            Debug.Print("SegmentsToPersistRefs called for list of " + segments.Count);

            List refs = new List();

            foreach (SketchSegment seg in segments)

            {

                object pid = mDoc.Extension.GetPersistReference3(seg);

                if (pid == null)

                {

                    throw new ApplicationException("SketchSegment GetPersistReference3 is null");

                }

                int errorCode;

                object obj = mDoc.Extension.GetObjectByPersistReference3(pid, out errorCode);

                if (errorCode != PERSIST_REF_OBJ_OK)

                {

                    // *** ENDS UP HERE with errorCode = 1 == INVALID ***

                    throw new ApplicationException("Cannot get object from PersistRef3 we just got");

                }

                refs.Add(pid);

            }

            return refs;

        }

SolidworksApi macros