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)

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


Attachments

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!

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