访问DateTime.Now

时间:2017-11-23 03:54:13

标签: c# .net timezone

以下c#代码在为.Net 4.5构建时,在Win 10开发框中作为控制台应用运行正常:

static void Main(string[] args)
    {
        try
        {
            Console.Write(DateTime.Now.ToString());
        }
        catch (Exception Ex)
        {
            Console.Write(Ex.Message);
        }

    }

但是当在带有.Net 4.6.1的Win 7盒子上运行时,它已经开始崩溃,显示以下消息:

    Unhandled Exception: System.Runtime.InteropServices.SEHException: External compo
    nent has thrown an exception.
       at System.TimeZoneInfo.TransitionTime.Equals(TransitionTime other)
       at System.TimeZoneInfo.CreateAdjustmentRuleFromTimeZoneInformation(RegistryTi
    meZoneInformation timeZoneInformation, DateTime startDate, DateTime endDate, Int
    32 defaultBaseUtcOffset)
       at System.TimeZoneInfo..ctor(TimeZoneInformation zone, Boolean dstDisabled)
       at System.TimeZoneInfo.GetLocalTimeZoneFromWin32Data(TimeZoneInformation time
    ZoneInformation, Boolean dstDisabled)
       at System.TimeZoneInfo.CachedData.GetCurrentOneYearLocal()
       at System.TimeZoneInfo.CachedData.GetOneYearLocalFromUtc(Int32 year)
       at System.TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc(DateTime time, Boolean&
    isAmbiguousLocalDst)
       at System.DateTime.get_Now()
       at DateCrashTest.Program.Main(String[] args) in c:\Users\Simon\Documents\Visu
    al Studio 2013\Projects\DateCrashTest\DateCrashTest\DateCrashTest\Program.cs:lin
    e 15

我有两个问题:

1)为什么异常没有被困?

2)为什么程序在具有相同.Net Framework和同一TimeZone的不同Win7盒子上运行正常?我在问题框中检查了.Net Framework Install,看起来没问题。这个问题最近出现了 - 几天前没有发生。重新启动没有帮助。

0 个答案:

没有答案