5

After migration to SDL Web 8, one piece of code in our C# TBB doesn't work anymore.

List<RepositoryLocalObject> componentList = newsKeyword.GetClassifiedItems(filter).ToList();

foreach (Component component in componentList)
{
    //_log.Debug("value:" + component.Content.Value);
    if (component.Schema.Title == "News")
    {
        //TO DO SOMETHING
    }
}

The component.Schema always returns null which triggers an error of:

Object reference not set to an instance of an object

But the fun fact is, after lots of attempts, we realized that the component.Schema is no longer null ONLY when we try to get the component.Content.Value (comment out the _log.Debug line).

Did anyone encounter such issue before?

  • 1
    Can you include the stack trace, which should be available in the event log. – Likhan Sep 9 '16 at 8:41
4

Sounds like an issue with lazy loading of TOM.NET objects.

In general, TOM.NET objects can be partially loaded (i.e. not all property values are retrieved). This typically happens when getting a list of objects like you are doing.

However, TOM.NET objects have lazy loading behavior: as soon as you access a property which has not been loaded yet, it will trigger a full load of the object and return the loaded property value. Convenient, but may be detrimental to performance if you unintentionally access such properties.

Anyway, it seems the list doesn't load the Schema property. But nevertheless, if you access the property, it should have triggered a full load.

If you access the Content property (which is also not loaded), you do trigger a full load and after that, the Schema property is also loaded.

BTW: you can see whether a TOM.NET object is fully loaded or not using i LoadState property. You can also explicitly trigger a full load using its Load method.

Bottom line: this looks like a bug, with a simple workaround (if the performance overhead of fully loading each item in the list is acceptable).

| improve this answer | |
2

This will be fixed in the next public version of the SDL Web. As workaround you can reload component before using its properties

   foreach (Component component in componentList)
    {
        component.Reload();
        if (component.Schema.Title == "News")
        {
            //TO DO SOMETHING
        }
    }

PS: note, this will not decrease performance in comparing with previous versions of the Tridion, as Component.Schema has never been preloaded in the scope of this list.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.