Bug 28300 - TimeZoneNotFoundException
Summary: TimeZoneNotFoundException
Status: REOPENED
Alias: None
Product: iOS
Classification: Xamarin
Component: General (show other bugs)
Version: XI 8.6.0
Hardware: Macintosh Mac OS
: Normal enhancement
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
URL:
: 33729 37543 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-03-22 00:00 UTC by Dillon Buchananq
Modified: 2017-07-26 13:59 UTC (History)
14 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Dillon Buchananq 2015-03-22 00:00:31 UTC
Analytics for one of my apps reports a fatal crash with a message of "TimeZoneNotFoundException" resulting from the following code

DateTime.Now.ToString()

Stacktrace (most recent call first):

  Module "CodeHub.iOS.AppDelegate", line 0, in Main
    Void Main(System.String[])
  Module "MonoTouch.UIKit.UIApplication", line 0, in Main
    Void Main(System.String[], System.String, System.String)
  Module "MonoTouch.UIKit.UIApplication", line 0, in Main
    Void Main(System.String[], IntPtr, IntPtr)
  Module "CodeHub.iOS.AppDelegate", line 0, in FinishedLaunching
    Boolean FinishedLaunching(MonoTouch.UIKit.UIApplication, MonoTouch.Foundation.NSDictionary)
  Module "System.DateTime", line 0, in get_Now
    System.DateTime get_Now()
  Module "System.TimeZone", line 0, in GetLocalTimeDiff
    System.TimeSpan GetLocalTimeDiff(System.DateTime)
  Module "System.CurrentSystemTimeZone", line 0, in GetUtcOffset
    System.TimeSpan GetUtcOffset(System.DateTime)
  Module "System.TimeZoneInfo", line 0, in get_Local
    System.TimeZoneInfo get_Local()
  Module "System.TimeZoneInfo", line 0, in CreateLocal
    System.TimeZoneInfo CreateLocal()
  Module "System.TimeZoneInfo", line 0, in GetMonoTouchData
    System.IO.Stream GetMonoTouchData(System.String, Boolean)

Using Xamarin.iOS 8.6.0.51 with LLVM compilation.
Affected Users iOS: 8.2

I have been unable to reproduce locally but I have 4 crashes (all from the same user) from use out in the field.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2015-03-23 09:55:38 UTC
Do you know where your user is located?
Comment 2 Sebastien Pouliot 2015-03-23 20:09:19 UTC
We'll definitively need a bit more information about this. While not 100% identical the following code should exercise every time zone available on a device and it works fine on my iPhone6+ with iOS 8.2. 

	foreach (var name in NSTimeZone.KnownTimeZoneNames) {
		TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById (name);
		Assert.NotNull (tzi.GetUtcOffset (DateTime.Now), name);
	}
Comment 3 Marcin Cieślak 2015-06-08 04:33:03 UTC
If the timezone is not set (no $TZ set, no "/etc/localtime": "UTC" is assumed), this might be https://bugzilla.xamarin.com/show_bug.cgi?id=30360
Comment 4 Sebastien Pouliot 2015-09-10 22:23:39 UTC
*** Bug 33729 has been marked as a duplicate of this bug. ***
Comment 5 Alex Soto [MSFT] 2015-09-14 11:19:00 UTC
Tested 422 different TimeZones using iPhone Simulator and a bash script all of them worked as expected

Results: https://gist.github.com/dalexsoto/967342b3057277e6703c

In case anyone is interested in the bash script (Yes it can be improved but it just fits current test needs)

https://gist.github.com/dalexsoto/79f62ba5a36f23a74f1f

@Dillon, could you provide more details like which timezone is the one you are having issues? Or where your user is located? We need more info in order to track this down properly :)
Comment 6 Dillon Buchananq 2015-09-14 21:15:05 UTC
@Alex, unfortunately, the error collection mechanism I have setup does not have the resolution to provide me with any idea where these users are located. This is all the info I have on the errors (71 of them in total over 6 months)

http://sentry.dillonbuchanan.com/codehub/codehub-ios/group/465/
Comment 7 Alex Soto [MSFT] 2015-09-14 21:32:44 UTC
Hey @Dillon

Any chance you could create a small testcase that excercices the TimeZone/DateTime code you are using? I might not be triggering the same conditions that you have :) [The devil is on the small details]
Comment 8 Christopher Conover 2015-10-27 09:59:05 UTC
I ran into this issue as well with a subset of our users. The stacktrace I have is similar to the one already provided. It seems to occur whenever a time zone conversion is done. So any calls to DateTime.Now, ToLocalTime(), ToUniversalTime(), etc. raise this exception. I of course was unable to reproduce the issue myself. One additional piece of information I do have is the one user I was able to connect with who has this issue jail broke their phone. I'm not sure if that is relevant.
Comment 9 Sebastien Pouliot 2015-10-27 10:26:30 UTC
> has this issue jail broke their phone

Thanks, this was something we've been asking ourselves. Do you have any other details about that phone, e.g. model (CPU) and iOS version

Our tests covers every time zones and we have not been able to find an iOS version that would lead to this exception.
Comment 10 Christopher Conover 2015-10-27 10:38:49 UTC
He's on an iPhone 6+

Version: 8.4 (12H143)
Model: MGCU2LL/A

This user is a friend of mine so I can get any more information that is needed. Let me know.
Comment 11 Marcin Cieślak 2015-10-29 14:44:56 UTC
As iOS and BSD have some common heritage, I have lots of problems getting timezone files to be read properly on FreeBSD:

https://bugzilla.xamarin.com/show_bug.cgi?id=30360#c31

1) part of it is related to the incorrect byte swapping to get the endianness right ("Index (zero based) must be greater than or equal to zero and less than the size of the argument list." exception).

2) part of the issue is a requirement (coming from Windows) is that adjustment 
rules specified in adjustmentRules parameter are not in chronological order ("System.InvalidTimeZoneException: adjustment rules specified in adjustmentRules
parameter are not in chronological order").

Endianness issue got addressed on my end with https://github.com/mono/mono/pull/1982 but that patch does not seem to work everywhere. 

This needs further testing, but this might be a hint for the iOS problems as well.
Comment 13 Christopher Conover 2015-11-24 10:27:07 UTC
This bug is still marked as NEEDINFO. What more info is needed?
Comment 14 Rolf Bjarne Kvinge [MSFT] 2015-11-24 12:04:53 UTC
@Christopher, can you execute the following on the device in question?

	Console.WriteLine ("LocalTimeZone: {0}", NSTimeZone.LocalTimeZone);
	Console.WriteLine ("LocalTimeZone.Data: {0}", NSTimeZone.LocalTimeZone?.Data);
	Console.WriteLine ("LocalTimeZone.Data.Length: {0}", NSTimeZone.LocalTimeZone?.Data?.Length);
Comment 15 Christopher Conover 2015-11-24 12:12:19 UTC
I no longer have access to the device in question unfortunately. Maybe someone else who has a user experiencing this issue can run that code.
Comment 16 Sebastien Pouliot 2016-04-12 15:54:19 UTC
*** Bug 37543 has been marked as a duplicate of this bug. ***
Comment 17 manuel 2016-05-12 10:40:22 UTC
Guys

We also have this situation logged. For us it is happening at least with 1 user in Paris, France, Language fr-fr (Google Analytics info) 

Device = iPhone5,2; 

System Version = Version 9.3.1 (Build 13E238); 

Error = System.TimeZoneNotFoundException: Exception of type 'System.TimeZoneNotFoundException' was thrown. at System.TimeZoneInfo.GetMonoTouchData (System.String name, Boolean throw_on_error) <0x4baec0 + 0x000c8> in <filename unknown>:0 at System.TimeZoneInfo.CreateLocal () <0x4bae24 + 0x00027> in <filename unknown>:0 at System.TimeZoneInfo.get_Local () ...

Although i think it is also happening with other versions, it is for sure with an app compiled with 

######
XS Config
#####

Xamarin Studio Business
Version 6.0 (build 5104)
Installation UUID: 5f421f3f-40c4-4caa-8ae3-df7a8094edf4
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch/81f38a9) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000142

Xamarin.Profiler
Version: 0.0.0.0
Location: /Users/nativolabs/Documents/profiler-mac-0.9-0/XamarinProfiler.Mac.app/Contents/MacOS/XamarinProfiler.Mac

Apple Developer Tools
Xcode 7.3 (10183.3)
Build 7D175

Xamarin.iOS
Version: 9.8.0.295 (Xamarin Business)
Hash: 12d988e
Branch: cycle7
Build date: 2016-04-25 13:42:06-0400

Xamarin.Android
Version: 6.1.0.48 (Xamarin Business)
Android SDK: /Users/nativolabs/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 25.1.3
SDK Platform Tools Version: 23.1
SDK Build Tools Version: 23.0.3

Java SDK: /usr
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Android Player
Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

Xamarin.Mac
Not Installed

Xamarin Inspector
Version: 0.7.0.0
Hash: 2a5f6e9
Branch: master
Build date: Thu Mar 31 18:37:26 UTC 2016

Build Information
Release ID: 600005104
Git revision: 1345d355d4f1b9677d91e1290a6034e2047bdf36
Build date: 2016-04-26 12:21:45-04
Xamarin addins: 7d85147c75b6dbb4b351906636ef76fdf60307c2
Build lane: monodevelop-lion-cycle7

Operating System
Mac OS X 10.11.4
Darwin Nativos-MacBook-Pro.local 15.4.0 Darwin Kernel Version 15.4.0
    Fri Feb 26 22:08:05 PST 2016
    root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

Enabled user installed addins
Xamarin Inspector 0.7.0.0
Comment 18 manuel 2016-05-12 23:29:01 UTC
By searching backward until October 2015, we did find 2 other users with the following features
 
Country = Portugal
Device = iPhone4,1; 
System Version = Version 8.3 (Build 12F70);

Country = Cambodia
Device = iPhone5,1; System Version = Version 9.2.1 (Build 13D15); 

This really seems some side effect, but when it happens, it seems it does always happen   and it is not a random thing
Comment 19 manuel 2016-05-12 23:43:56 UTC
just forgot languages

Portugal - Language fr
Cambodia - Language km-kh
Comment 20 Sebastien Pouliot 2016-05-13 00:22:12 UTC
@Manuel we have not been able to duplicate this ourselves. However we're pretty sure this happens exclusively on jailbroken devices (which explains why it's not random). Somehow it makes them unable to report the list of supported timezones, which several API depends on.
Comment 21 manuel 2016-05-13 09:42:10 UTC
ok, it makes sense. We do capture this through the log mechanism that we have reporting to Google Analytics. Any advice to detect jailbroken devices? 

I see that Xamarin Insights does it. Anyway we'll google it and try to add that to our logs.

Although sampling stuff in Google Analytics makes it very difficult to have a good notion of this very occasional issues, our very representative statistics are saying that French speakers are the ones with more jail broken devices in the world! :)
Comment 22 Alex Soto [MSFT] 2016-06-08 19:57:07 UTC
Reopened, We think this just happens on jailbroken devices, Still DateTime.Now should *not* throw under any circumstances so we should fix this, maybe just use UTC as a fallback?
Comment 23 manuel 2016-06-08 23:06:18 UTC
Alex that can be a dangerous solution. It can put application functionality in jeopardy. In our case the perception of dates is super important.
Comment 24 Rolf Bjarne Kvinge [MSFT] 2016-06-09 09:37:09 UTC
I'm not sure it's a good idea to have a fallback TZ either. But at least we should be able to provide a more informational exception message that would make tracking this down simpler.
Comment 26 Dillon Buchananq 2016-07-30 22:42:06 UTC
Just got another user in Germany who has reported seeing this TimeZoneNotFoundException. He's using an app of mine that was recently compiled (last week) using the latest Xamarin.

Xamarin.iOS
Version: 9.8.1.4 (Xamarin Business)
Hash: 3cf8aae
Branch: c7sr0
Build date: 2016-06-20 16:09:58-0400
Comment 27 Dillon Buchananq 2016-07-30 22:42:33 UTC
Forgot to post the issue page if anyone cares: https://bitbucket.org/thedillonb/codebucket/issues/15/timezone-exception
Comment 28 Riz Mawani 2016-09-17 22:28:22 UTC
For anybody who is still struggling with the TimeZoneNotFoundException, I managed to find a workaround that was originally found by HHumbert on Reddit. 

Use NewTerminal (or any other Terminal emulator) or SSH into the offending device, login as superuser and type in the following, verbatim:

cd /var/db/timezone
mv zoneinfo zoneinfo.broken
ln -s /usr/share/zoneinfo.default zoneinfo

HHumbert explains the issue and circumstances of his find more clearly in his Reddit post, as follows:

https://www.reddit.com/r/jailbreak/comments/3ll1rf/tutorial_solution_how_to_fix_broken_timezone_in/

The above seemed to do the trick for me and I hope it helps others as well!

RM
Comment 29 Al Clark [MSFT] 2017-07-26 13:59:28 UTC
> But at least we should be able to provide a more informational exception message that would make tracking this down simpler. (Comment 24)

Changing priority to Enhancement Request.

Note You need to log in before you can comment on or make changes to this bug.