You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: EasyPostObject.GetHashCode() throws null error when Id is null #678
When it [automatically] compares 2 child class objects of EasyPostObject (that are created manually and the Id wasn't set yet) it throws System.NullReferenceException: Object reference not set to an instance of an object.
What was expected?
The code should check first if the Id is null:
public override int GetHashCode()
{
return base.GetHashCode() ^ (Id ?? "").GetHashCode();
}
Sample Code
List<Shipment>ShipmentList=newList<Shipment>();// Replace the (not yet purchased) copies in ShipmentList with the purchased boxes.foreach(varboxinCurrentOrder.Shipments){varsameFound=ShipmentList.FirstOrDefault(sh =>string.IsNullOrEmpty(sh.TrackingCode)&&sh.Parcel?.Weight==box.Parcel?.Weight&&sh.CarrierAccounts?.Any(c =>c.Readable?.ToUpper()==box.SelectedRate?.Carrier?.ToUpper())==true);if(sameFound!=null){//EasyPostExt.MakeSureItHasAnId(sameFound); // Prevents the error.ShipmentList.Remove(sameFound);// Error happens here!}ShipmentList.Add(box);}
Relevant logs
System.NullReferenceException: Object reference not set to an instance of an object.
at EasyPost._base.EasyPostObject.GetHashCode()
at EasyPost._base.EasyPostObject.Equals(Object obj)
at System.Collections.Generic.ObjectEqualityComparer`1.IndexOf(T[] array, T value, Int32 startIndex, Int32 count) at System.Collections.Generic.List`1.IndexOf(T item)
at System.Collections.Generic.List`1.Remove(T item) at EasyPostShipping.ShipmentOrder.Buy(Rate rate) in C:\Users\user\source\repos\EasyPost\EasyPostShipping\Model\ShipmentOrder.cs:line 798 at EasyPostShipping.EasyPostShippingController.<Ship>d__191.MoveNext() in C:\Users\user\source\repos\EasyPost\EasyPostShipping\Controller\EasyPostShippingController.cs:line 2520
Activity