So in my code I have a list of items:-
public List<IssueReceiveWorkOrderItemModel> IssueReceiveWorkOrderItems { get; set; } = new List<IssueReceiveWorkOrderItemModel>();
and it is being used in this code:-
foreach (IssueReceiveWorkOrderItemModel item in IssueReceiveWorkOrderItems)
{
if (items.Any(o => !string.IsNullOrEmpty(o.Stock_Code)))
{
IssueReceiveWorkOrderItem issueReceiveWorkOrderItem = items.FirstOrDefault(o => o.Stock_Code.Equals(item.Stock_Code, StringComparison.CurrentCultureIgnoreCase));
if (issueReceiveWorkOrderItem != null)
{
item.DifferenceQty = issueReceiveWorkOrderItem.Qty_Allocated - item.Qty_Allocated;
}
}
else
{
item.DifferenceQty = -item.Qty_Allocated;
}
}
there were some issues after debugging I found out that the IssueReceiveWorkOrderItemModel item, is null when IssueReceiveWorkOrderItems has 3 items, the foreach loop is looping 3 times but the item is always null which is causing issue
I have checked my whole codebase there is no other duplicate for class IssueReceiveWorkOrderItemModel, this is my class:-
public class IssueReceiveWorkOrderItemModel
{
public string Stock_Code { get; set; }
public string Description { get; set; }
public decimal? Qty_Allocated { get; set; }
public decimal? DifferenceQty { get; set; }
}
have anyone faced this type of issue before ?
user23302679 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.