Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ArgumentOutOfRangeException: Not a valid calendar for the given culture. Parameter name: value

Discussion in 'Editor & General Support' started by anujmar27, May 18, 2021.

  1. anujmar27

    anujmar27

    Joined:
    Aug 24, 2019
    Posts:
    2
    i have an app published on google play store,i have published update for that app after upgrading the unity editor from 2019.4.17 to 2020.3.7 ,but after the update some of the user are getting the date time error ,whlie other able to use the application without any issues,i have tested it on all available device with me and found that on samsung and Huawei devices this error is occurs and app crashed
    "ArgumentOutOfRangeException: Not a valid calendar for the given culture. Parameter name: value".

    someone please help ?
     
    ShenDh likes this.
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,749
    Here are some notes on IndexOutOfRangeException and ArgumentOutOfRangeException:

    http://plbm.com/?p=236

    This sounds related to localization so you can probably focus your investigations there if you localized your app.

    If you did not localize your app, then to help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.

    Doing this should help you answer these types of questions:

    - is this code even running? which parts are running? how often does it run? what order does it run in?
    - what are the values of the variables involved? Are they initialized? Are the values reasonable?

    Knowing this information will help you reason about the behavior you are seeing.

    You can also put in Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene

    You could also just display various important quantities in UI Text elements to watch them change as you play the game.

    If you are running a mobile device you can also view the console output. Google for how on your particular mobile target.

    Here's an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

    https://forum.unity.com/threads/coroutine-missing-hint-and-error.1103197/#post-7100494
     
  3. barkovandrei

    barkovandrei

    Joined:
    Nov 18, 2015
    Posts:
    7
    i've got same reports after update projects to Unity 2020.3.9f1 on both platforms ios and android!
    i can't reproduce this on my devices.

    this is report from firebase crashlytics:

    Code (CSharp):
    1. Non-fatal Exception: java.lang.Exception: ArgumentOutOfRangeException : Not a valid calendar for the given culture.
    2. Parameter name: value
    3.        at System.Globalization.DateTimeFormatInfo.set_Calendar(System.Globalization.DateTimeFormatInfo)
    4.        at System.Globalization.CultureInfo.get_DateTimeFormat(System.Globalization.CultureInfo)
    5.        at System.Globalization.CultureInfo.GetFormat(System.Globalization.CultureInfo)
    6.        at System.Globalization.DateTimeFormatInfo.get_CurrentInfo(System.Globalization.DateTimeFormatInfo)
    7.        at System.DateTime.ToString(System.DateTime)
    example usage causing the problem:
    DateTime.Now.AddMinutes(60).ToShortString()

    reports point to any calls datetime.tostring in any variations
     
    Last edited: Jun 17, 2021
  4. Andrew-Carvalho

    Andrew-Carvalho

    Joined:
    Apr 22, 2013
    Posts:
    39
    Are you by chance using ToString on a DateTime object with a format string? It's possible the format string you are providing isn't valid for the current context, as some cultures have different calendars.

    To verify, change your device language to Saudi Arabian Arabic and try running the application, as their dates are formatted differently.

    You can either choose a format that works with all cultures, or pass a second argument of IFormatProvider to the ToString call provided by the InvariantCulture if you want dates to always be printed the same way, regardless of device language region.
     
  5. Archi_16

    Archi_16

    Joined:
    Apr 7, 2017
    Posts:
    84
    This problems came on 2020 version of Unity.
    same code worked perfect on 2018.4.3.

    After upgrading my project, i got ~10k non fatal errors on firebase with this issue
     
    unity_matchday likes this.
  6. Archi_16

    Archi_16

    Joined:
    Apr 7, 2017
    Posts:
    84
    Solution.
    Just add this somewhere, You don't need to call this function. It will work on compilation and calendars will be added automatically

    public void AddCallendars()
    {
    new System.Globalization.GregorianCalendar();
    new System.Globalization.PersianCalendar();
    new System.Globalization.UmAlQuraCalendar();
    new System.Globalization.ThaiBuddhistCalendar();
    }
     
    Last edited: Sep 24, 2021
    andrew_pearce_, r35, shx and 7 others like this.
  7. QDao

    QDao

    Joined:
    Jun 11, 2021
    Posts:
    7
    It doesn't work
     
  8. barkovandrei

    barkovandrei

    Joined:
    Nov 18, 2015
    Posts:
    7
    Solution works for me: add link.xml file like this to Assets folder

    <linker>
    <assembly fullname="mscorlib">
    <namespace fullname="System.Globalization" preserve="all"/>
    </assembly>
    <assembly fullname="System.Globalization.*Calendar" preserve="all"/>
    </linker>

    After a few days of research, I found it somewhere on the forums. Now this solution works and crash reports are no longer received.
    As far as I understand, this happens because there is a strip of unnecessary code by the compiler
     
  9. wanitek1

    wanitek1

    Joined:
    May 22, 2021
    Posts:
    2
    If you're just calculating timespan then I think you can try using DateTime.UtcNow instead of DateTime.Now.
     
  10. FahmyEldeeb

    FahmyEldeeb

    Joined:
    May 11, 2021
    Posts:
    3
    This worked for me thanks a ton, used invariant culture as a format in ToString
     
  11. maax511

    maax511

    Joined:
    Jan 21, 2021
    Posts:
    6
    Worked perfectly for me. Solution with AddCalendars() did nothing. Solution with XML file crashed builds and only this one really fixed the problem.
     
  12. Shefich

    Shefich

    Joined:
    May 23, 2013
    Posts:
    106
    Unity 2020.3.34f1 / IL2CPP / .NET4.x
    Made project on Windows and released on Android.
    Have the same issue.

    Code (CSharp):
    1. Non-fatal Exception: java.lang.Exception: ArgumentOutOfRangeException : Not a valid calendar for the given culture.
    2. Parameter name: value
    3.        at System.Globalization.DateTimeFormatInfo.set_Calendar(System.Globalization.DateTimeFormatInfo)
    4.        at System.DateTimeFormat.ExpandPredefinedFormat(System.DateTimeFormat)
    5.        at System.DateTimeFormat.Format(System.DateTimeFormat)
    I'm using DateTime.Now and there is no possibility to use UtcNow.
    BTW issue appeared after I switched to unity 2020. Unity 2019 hasn't such issue. Also it appears on only on devices with special calendar systems. For ex.: Thai
     
  13. anujmar27

    anujmar27

    Joined:
    Aug 24, 2019
    Posts:
    2

    reimport all assets and try switching to some other platform and back to your targeted platform, this worked for me.I do this every time I switch the editor version
     
    Shefich likes this.
  14. Babybus_Study

    Babybus_Study

    Joined:
    Oct 31, 2016
    Posts:
    14
    This Method works for me!
     
  15. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    164
    It took me some time to find a bug. Thanks @Archi_16, you pushed me to correct direction. I was trying to get a name of the month but I was creating date new DateTime(1, monthIndex, 1) which of course is outside of the range for UmAlQuraCalendar which is 1900-2077. Instead I had to use current year: new DateTime(DateTime.Now.Year, monthIndex, 1) If someone is facing the same issue, make sure to double check that all manually created dates are not going outside of range. BTW ThaiBuddhistCalendar seems to be working fine, even though current Thai years is 2565.
     
    Archi_16 likes this.