Bug 56499 - DateTime.Now throws exception if /etc/localtime symlink destination missing
Summary: DateTime.Now throws exception if /etc/localtime symlink destination missing
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 5.0 (2017-02)
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-05-16 12:57 UTC by Sander Saares
Modified: 2017-05-24 18:56 UTC (History)
3 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 GitHub or Developer Community 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 Sander Saares 2017-05-16 12:57:11 UTC
In the current ubuntu:xenial-20170510 (latest 16.04) container images published on Docker Hub, there is an /etc/localtime symlink that points to a non-existing timezone file because the tzdata package is not installed and no timezone information actually exists at the symlink destination.

In this type of situation, the DateTime.Now getter throws the following exception:

System.IO.FileNotFoundException: Could not find file "/etc/localtime"
File name: '/etc/localtime'
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x001d8] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) [0x00000] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare)
  at System.IO.File.OpenRead (System.String path) [0x00000] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at System.TimeZoneInfo.FindSystemTimeZoneByFileName (System.String id, System.String filepath) [0x0000e] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at System.TimeZoneInfo.CreateLocal () [0x000cc] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at System.TimeZoneInfo.get_Local () [0x00009] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at System.TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc (System.DateTime time, System.Boolean& isAmbiguousLocalDst) [0x00000] in <4dc8ec68b0964e099af86e50301f5f3c>:0
  at System.DateTime.get_Now () [0x00008] in <4dc8ec68b0964e099af86e50301f5f3c>:0
Comment 1 Marcin Cieślak 2017-05-16 19:40:40 UTC
A completely untested fix is at

https://github.com/mono/mono/compare/master...saper:bug56499?expand=1
Comment 2 Alexander Köplinger [MSFT] 2017-05-24 18:56:53 UTC
I merged the above PR, thanks!