Getting a System.ArgumentNullException calling IsOfficialPublicHolidayByCounty
See original GitHub issueHi Tino, First of all, just wanted to say this is a great library 🥇 When I am checking a date that is a holiday for county code “GB-ENG” then I get an exception on items where they do not have any Counties (null). {“Value cannot be null.\r\nParameter name: source”}
public static bool IsOfficialPublicHolidayByCounty(DateTime date, CountryCode countryCode, string countyCode)
{
var items = GetPublicHoliday(countryCode, date.Year);
return items.Where(o => o.Date.Date == date.Date && o.Counties.Contains(countyCode) && o.CountyOfficialHoliday).Any();
}
However, what I really want is to find if a date is a holiday in the UK but exclude any holidays that are specifically for Northern Ireland or Scotland, so I created the following method :
return IsOfficialPublicHolidayExcludeCounties(date, CountryCode.GB, new string[] { "GB-NIR", "GB-SCT" });
public static bool IsOfficialPublicHolidayExcludeCounties(DateTime date, CountryCode countryCode, string[] countyCodes)
{
var items = DateSystem.GetPublicHoliday(countryCode, date.Year);
return items.Where(o => o.Date.Date == date.Date && (o.Counties == null || o.Counties.Except(countyCodes).Any()) && o.CountyOfficialHoliday).Any();
}
Thought it might help
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Getting a System.ArgumentNullException calling ...
I'm only writing unit tests so for the time being I can just use that instead of calling IsOfficialPublicHolidayByCounty().
Read more >How to Handle the ArgumentNullException in C# | Rollbar
An object returned from a method call is then passed as an argument to a second method, but the value of the original...
Read more >ArgumentNullException Class (System)
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method that does not accept it...
Read more >c# - Why ArgumentNullException? Why not System. ...
Count() is an extension method on IEnumerable<T> , declared in System.Linq.Enumerable - so you're actually calling: Enumerable.
Read more >Expected: <System.ArgumentNullException> But was : null
I have a method under a class Manager called GetProject() that I need ... id) { //calls a service to get the projects...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Lol, and I forgot a set of brackets. Or more correctly ReSharper did. It should be:
items.Any(o => o.Date.Date == queryTime.Date && ((o.Counties==null)||o.Counties.Contains(“GB-ENG”)) && o.CountyOfficialHoliday)
If this issue done?