{"record":{"id":"57dad62aef2e97c4","repo":"bchavez/Bogus","slug":"nameof-year-must-be-between-1854-and-2039","errorCode":null,"errorMessage":"{nameof(year)} must be between 1854 and 2039.","messagePattern":"(.+?) must be between 1854 and 2039\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"Source/Bogus/Extensions/Norway/ExtensionsForNorway.cs","lineNumber":87,"sourceCode":"\n      if (1854 <= year && year <= 1899)\n      {\n         from = 500;\n         to = 749;\n      }\n      else if (1900 <= year && year <= 1999)\n      {\n         from = 0;\n         to = 499;\n      }\n      else if (2000 <= year && year <= 2039)\n      {\n         from = 500;\n         to = 999;\n      }\n      else\n      {\n         throw new ArgumentOutOfRangeException(nameof(year), $\"{nameof(year)} must be between 1854 and 2039.\");\n      }\n\n      int individualNumber = gender == DataSets.Name.Gender.Female ? r.Even(from, to) : r.Odd(from, to);\n\n      return individualNumber.ToString(\"D3\");\n   }\n\n   private static bool GenerateChecksum(string birthDate, string individualNumber, out string checksum)\n   {\n      int d1 = int.Parse(birthDate.Substring(0, 1));\n      int d2 = int.Parse(birthDate.Substring(1, 1));\n      int m1 = int.Parse(birthDate.Substring(2, 1));\n      int m2 = int.Parse(birthDate.Substring(3, 1));\n      int y1 = int.Parse(birthDate.Substring(4, 1));\n      int y2 = int.Parse(birthDate.Substring(5, 1));\n      int i1 = int.Parse(individualNumber.Substring(0, 1));\n      int i2 = int.Parse(individualNumber.Substring(1, 1));\n      int i3 = int.Parse(individualNumber.Substring(2, 1));","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/bchavez/Bogus/blob/6ece18c5c22648ab4606e45a0aaf2f07fc5259e4/Source/Bogus/Extensions/Norway/ExtensionsForNorway.cs#L69-L105","documentation":"ExtensionsForNorway.Fodselsnummer's individual-number generator covers only 1854-1899, 1900-1999, 2000-2039. Any other birth year throws ArgumentOutOfRangeException. These ranges reflect the real Norwegian fødselsnummer allocation rules.","triggerScenarios":"Calling person.Fodselsnummer() on a Person whose DateOfBirth.Year is below 1854 or above 2039.","commonSituations":"Setting DateOfBirth to a date outside the supported era (e.g. a 2100 future-date fixture) and then generating a Norwegian national ID.","solutions":["Constrain Person.DateOfBirth to 1854-2039 before calling Fodselsnummer.","Use f.Date.Between(new DateTime(1900,1,1), DateTime.Today) for realistic birth dates.","Do not set DateOfBirth to dates beyond 2039 for Norwegian IDs."],"exampleFix":"// before\nperson.DateOfBirth = new DateTime(1850, 1, 1);\nvar fn = person.Fodselsnummer();\n\n// after\nperson.DateOfBirth = f.Date.Between(new DateTime(1920,1,1), DateTime.Today);\nvar fn = person.Fodselsnummer();","handlingStrategy":"validation","validationCode":"int year = person.DateOfBirth.Year;\nif (year < 1854 || year > 2039)\n    throw new ArgumentOutOfRangeException(nameof(year), \"Norwegian fødselsnummer requires 1854-2039.\");\nvar fn = person.Fodselsnummer();","typeGuard":"static bool NorwegianYearOk(int y) => y >= 1854 && y <= 2039;","tryCatchPattern":null,"preventionTips":["Keep birth years within 1854-2039 for Norwegian IDs.","Do not push DateOfBirth beyond 2039 even for future-dated fixtures.","Generate dates with f.Date.Between(new DateTime(1900,1,1), DateTime.Today)."],"tags":["norway","fodselsnummer","date-validation","national-id"],"backgroundTag":null,"analyzedSha":"6ece18c5c22648ab4606e45a0aaf2f07fc5259e4","analyzedAt":"2026-08-13T21:08:15.463Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}