Bug 1790 - 'System.TimeZoneNotFoundException' When attempting any form of time conversion
Summary: 'System.TimeZoneNotFoundException' When attempting any form of time conversion
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 5.0
Hardware: Other Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2011-10-31 07:05 UTC by bugzilla
Modified: 2012-01-05 11:19 UTC (History)
4 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description bugzilla 2011-10-31 07:05:53 UTC
Currently, when I attempt any of the time conversion methods in System.TimeZoneInfo, such as System.TimeZoneInfo.ConvertTime() I receive the following error:

Details: System.TimeZoneNotFoundException: Exception of type 'System.TimeZoneNotFoundException' was thrown.
  at System.TimeZoneInfo.get_Local () [0x00000] in <filename unknown>:0 
  at System.TimeZoneInfo.ConvertTime (DateTime dateTime, System.TimeZoneInfo destinationTimeZone) [0x00000] in <filename unknown>:0 

The code works fine on the iOS simulator, but when placed on a device the code will not run and throws an error.
Comment 1 bugzilla 2011-10-31 07:32:15 UTC
I have created a simplified example of the issue available at:
https://github.com/perkof/TimeZoneConvert

When you run this in the simulator you should see the text "Nothing has happened", however when you run this on an actual device you will get an TimeZoneNotFoundException in its place.
Comment 2 Sebastien Pouliot 2011-11-02 15:59:45 UTC
The existing code reads data from the OS, e.g. /etc/localtime
That might be available when running from the simulator (on a Mac) but not when executed on the device.

Until a fix is available have a look at NSTimeZone to see if you can make it do what you require.
Comment 3 bugzilla 2011-11-03 02:15:43 UTC
Thanks Sebastien. 

I managed to create a work around to get my applications talking using the correct time :). I had a look at the mono source code and assumed the /etc/localtime to be the case - was unsure on how to fix it. 

I know that the local time can be determined on iOS using NSTimeZone.localTimeZone which could put you somewhere towards a fix :)
Comment 4 Sebastien Pouliot 2011-11-03 13:42:09 UTC
downgrading to 'major' since a workaround is possible
Comment 5 Sebastien Pouliot 2011-11-08 08:26:58 UTC
Fixed (for 5.1). We now initialize the BCL TimeZoneInfo from NSTimeZone since we cannot, when executed on devices, access the file system to get directly the required files.