11

We are using a slightly hacked version of the Tridion Reference Implementation as we are using 2009sp1 (don't ask!)

We have a lot of things working well but we have an issue with the function GetMultiComponentLinks.

In the function I can see the following code that I assume goes and gets the data model for the linked components

MethodInfo method = GetType().GetMethod("GetCompLink" + (multival ? "s" : String.Empty), BindingFlags.NonPublic | BindingFlags.Instance);
method = method.MakeGenericMethod(new[] { linkedItemType });
return method.Invoke(this, new object[] { items, linkedItemType });

However when this runs the method is always null. I can't seem to find any reference to GetCompLink either either in the TRI source or DD4T source. If someone can point me in the right direction I would greatly appreciate it!

9

Interesting one - somehow the Sdl.Web.DD4T.Mapping.DD4TModelBuilder.GetCompLink(s) methods got removed, probably by some over-zealous code analysis which detected un-used methods (as the only way they are called is by reflection). As the example models shipped with TRI do not use this (they always use String or Link types for linked content) it was never noticed. I dug out the original source:

private List<T> GetCompLinks<T>(IEnumerable<IComponent> components, Type linkedItemType)
{
    List<T> list = new List<T>();
    foreach (var comp in components)
    {
        list.Add((T)Create(comp, linkedItemType));
    }
    return list;
}

private T GetCompLink<T>(IEnumerable<IComponent> components, Type linkedItemType)
{
    return GetCompLinks<T>(components,linkedItemType)[0];
}

I added an issue to get this sorted for the next release, in the mean time you can add this code (it might need testing properly) to your web app.

UPDATE

You may also notice that these methods dont really need the linkedItemType parameter, you can replace with the following:

list.Add((T)Create(comp, typeof(T)));
  • Ahhh now it all makes sense. I'm glad it wasn't me just being stupid! I'll pop the code in and test it all out. Thanks a lot. – James Scott Nov 19 '14 at 8:58

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.