Try our conversational search powered by Generative AI!

Custom Line Item Property throws null reference exception

Vote:
 

Hi,

I have custom line item with name TreasuresLineItem

I have below line in ecf.order.config

The class looks like below

  public class TreasuresLineItem : LineItem
    {
        public TreasuresLineItem() : base()
        {
            Initialize();
        }

        public TreasuresLineItem(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            Initialize();
        }

        protected virtual void Initialize()
        {
          
        }

        public bool IsGift
        {
            get { return GetBool(MetaFieldsConstants.LineItem.IsGift); }
            set { this[MetaFieldsConstants.LineItem.IsGift] = value; }
        }

        public string Recipeints
        {
            get { return GetString(MetaFieldsConstants.LineItem.Recipients); }
            set { this[MetaFieldsConstants.LineItem.Recipients] = value; }
        }
}

When i try to add entry to cart and then cast it to TreasureLineItem. The system cast it successfully but accessing properties throws an null exception


/* Need entry for adding to cart */
var entry = CatalogContext.Current.GetCatalogEntry(cartLineItem.Code);
var lineItem = ch.AddEntry(entry, cartLineItem.Quantity, false, new CartHelper[] { }) as TreasuresLineItem;

Throws exception 

lineItem.IsGif accessing property throws exception

I have checked meta field exists in database and it is linked with TreasureLineItem, The database table for extended line item with column also exists.

Do you have any idea why it is happening like this?

#172403
Dec 01, 2016 23:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.