-
Notifications
You must be signed in to change notification settings - Fork 215
Description
I am encountering a NullReferenceException when calling MarketPlace.GetMarketPlaceByID(string id).
Cause:
The issue is caused by the static initialization order within the MarketPlace class. The static list _allMarketplaces is declared and initialized at the top of the class, before the individual static marketplace fields (like US, Canada, etc.) are defined.
Because C# initializes static fields in the order they appear in the source code, _allMarketplaces is populated with null values. When GetMarketPlaceByID is called, the LINQ FirstOrDefault call attempts to access .ID on a null object, leading to the crash:
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at FikaAmazonAPI.Utils.MarketPlace.GetMarketPlaceByID(String id)
Proposed Fix:
The _allMarketplaces list must be moved below the individual marketplace definitions to ensure they are instantiated before being added to the list.
Note: A PR (#906) has already been submitted by @babuscam to address this specific issue.
@abuzuhri, could you please review and merge this fix as it currently breaks the utility methods in the latest version?