We're facing a strange issue when using the GetItems method and passing each item within the returned collection to another method.
We are on Tridion 2011 GA.
The following the code is breaking:
private void foo(StructureGroup structureGroup, Session session, int counterTemp, int levels)
{
OrganizationalItemItemsFilter filtersg= new OrganizationalItemItemsFilter(session);
filtersg.Recursive = false;
IEnumerable<ItemType> itemtype = new List<ItemType> { ItemType.StructureGroup};
filtersg.ItemTypes = itemtype;
foreach (StructureGroup sg in structureGroup.GetItems(filtersg))
{
GetSiteMap(sg, counterTemp, levels);
}
}
private void GetSiteMap(StructureGroup sg, int counter, int levels)
{
logger.Info(sg.Id); //ok
logger.Info(sg.Title); //ok
logger.Info(sg.Directory); // null !?
}
However, if the sg.Directory is access prior to passing sg into the next method, all works fine:
private void foo(StructureGroup structureGroup, Session session, int counterTemp, int levels)
OrganizationalItemItemsFilter filtersg= new OrganizationalItemItemsFilter(session);
filtersg.Recursive = false;
IEnumerable<ItemType> itemtype = new List<ItemType> { ItemType.StructureGroup};
filtersg.ItemTypes = itemtype;
foreach (StructureGroup sg in structureGroup.GetItems(filtersg))
{
logger.Info(sg.Directory); //if printed here, all works fine down the line.
GetSiteMap(sg, counterTemp, levels);
}
}
private void GetSiteMap(StructureGroup sg, int counter, int levels)
{
logger.Info(sg.Id); //ok
logger.Info(sg.Title); //ok
logger.Info(sg.Directory); // ok }
}
It feels that there is something going on with the GetItems() method where it doesn't return the full object, and once passing the partially loaded object to the next method, it's not able to load the properties as if the original reference is lost.
Can someone please shed some light on what's happening here? Also, is it bad to pass TOM.NET objects between methods?
Thanks