question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting a System.ArgumentNullException calling IsOfficialPublicHolidayByCounty

See original GitHub issue

Hi 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:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrueCopecommented, Apr 28, 2017

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)

0reactions
tinohagercommented, May 1, 2017

If this issue done?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found