0

I'm trying to set a list, but I get an object not set to an instance error. If I remove the List<> in the PricingList class it works fine. I'm sure this is something simple I'm missing, error is generated in the req.pricingList.plist.Add(prlist) line.

class Program
{
    static void Main(string[] args)
    {
        //   Do Test 
        PriceRequest req = new PriceRequest();
        PricingHeader hdr = new PricingHeader();
        Pricing prlist = new Pricing();
        PricingList lst = new PricingList();

        req.pricingList = lst;
        req.pricingList.plist.Add(prlist);
        req.pricingList.plist[0].quantity = "1";

        Console.WriteLine("  ");
    }
}

public class PriceRequest
{

    public PricingHeader pricingHeader { get; set; }
    public PricingList pricingList { get; set; }
}

public class PricingHeader
{
    public string supplierCode { get; set; }
    public string accountNumber { get; set; }
    public string accountNumberReference { get; set; }
    public string version { get; set; }
}

public class PricingList
{
    public List<Pricing> plist { get; set; }
}

public class Pricing
{
    public string quantity { get; set; }
    public string unitPrice { get; set; }
    public string suplierPartId { get; set; }
}
Mark T
  • 1

1 Answers1

-1

You do not appear to have initialized the plist property of your PricingList instance.

Eric
  • 1,737
  • 1
  • 13
  • 17