Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Naveed Ali 161 posts 426 karma points
    Jun 02, 2016 @ 09:33
    Naveed Ali
    0

    Urgent Help!! cast issue

    Hi,

    I need some urgent help on this block of code which is throwing up error every time. I get a an error of:

    'System.InvalidCastException' occurred in System.Core.dll

    This is the block of code..anyone have any idea the correct way to do this. it is slightly difficult for me to pin point the issue as I did not write the code.

        public List<PageWithSidebar> ProductRanges
        {
            get
            {
                var ranges = this.GetPropertyValue<List<IPublishedContent>>("productRanges");
                //return ranges != null ? ranges.Cast<PageWithSidebar>().ToList() : new List<PageWithSidebar>();
                return ranges != null ? ranges.Cast<PageWithSidebar>().ToList() : new List<PageWithSidebar>();
            }
        }
    

    Thanks

    Nav

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 02, 2016 @ 09:51
    Jeavon Leopold
    0

    Hi Nav,

    You need to work out how a List<IPublishedContent> can be cast to PageWithSidebar.

    Some things to look for:

    • Is ModelsBuilder or any Model mapper being used?
    • What data type is "productRanges" and does it have a custom value converter?
    • Is there a type converter?

    Jeavon

  • Naveed Ali 161 posts 426 karma points
    Jun 02, 2016 @ 10:43
    Naveed Ali
    0

    I sorted it I had to change the Ienumerable to "list"..The code above had this change just before I tested it lol

    Thanks for the reply :-)

    Nav

Please Sign in or register to post replies

Write your reply to:

Draft