none
Accessing DateTime - An application error occurred: Common Language Runtime detected an invalid program RRS feed

  • Question

  • Using Visual Studio 2010 (10.0.40219.1 SP1Rel) under Windows 7 Pro 64-bit.

    Steps to reproduce:

    1) New project - Visual C# - .NET 2.0 - Windows Forms Application - Name - TestingBug;

    2) Form1.cs - View code - Add 'DateTime d = DateTime.Now;' before constructor; Now source looks:

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace TestingBug
    {
    	public partial class Form1 : Form
    	{
    		DateTime d = DateTime.Now;
    		public Form1()
    		{
    			InitializeComponent();
    		}
    	}
    }
    
    

     


    3) Right click on project - Properties - Build - Platform target: change to x64;

    4) Save all;

    5) Start Debug / Run;

    Window is not shown and exception is thrown:

    ---

    System.InvalidProgramException was unhandled
      Message=Common Language Runtime detected an invalid program.
      Source=mscorlib
      StackTrace:
           at System.CurrentSystemTimeZone.GetDaylightChanges(Int32 year)
           at System.CurrentSystemTimeZone.GetUtcOffsetFromUniversalTime(DateTime time, Boolean& isAmbiguousLocalDst)
           at System.CurrentSystemTimeZone.ToLocalTime(DateTime time)
           at System.DateTime.get_Now()
           at TestingBug.Form1..ctor() in c:\temp\TestingBug\TestingBug\Form1.cs:line 13
           at TestingBug.Program.Main() in c:\temp\TestingBug\TestingBug\Program.cs:line 17
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    ---

    Output window shows:

    ---

    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'c:\temp\TestingBug\TestingBug\bin\Debug\TestingBug.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_64\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    The thread 'vshost.NotifyLoad' (0x103c) has exited with code 0 (0x0).
    The thread 'vshost.LoadReference' (0xe10) has exited with code 0 (0x0).
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'c:\temp\TestingBug\TestingBug\bin\Debug\TestingBug.exe', Symbols loaded.
    A first chance exception of type 'System.InvalidProgramException' occurred in mscorlib.dll
    'TestingBug.vshost.exe' (Managed (v2.0.50727)): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    The program '[2804] TestingBug.vshost.exe: Managed (v2.0.50727)' has exited with code 0 (0x0).
    ---

    Other observations so far:

    1) It happens only on one particular computer with the same config as others;

    2) It happens only on x64 build;

    3) It happens in any .NET program that accesses DateTime class;

    4) I can not reproduce this anywhere else;

    5) Tried to repair Windows with: sfc /scannow -- result - 'Windows Resource Protection did not find any integrity violations.';

    6) Searching Google / Bing - no similar problems;

    7) It happens on both - debug and release builds;

     

    Now the question: Is there a way to solve this without reinstalling Windows? I can provide any additional info necessary to solve this.


    • Edited by MarisBo Tuesday, August 23, 2011 4:26 PM added info
    Tuesday, August 23, 2011 4:22 PM

Answers

  • Could you please check the Windows Event Log?

    If the TimeZone or DayLightSaving on that machine is different agianst other machines, you can change the TimeZone and DayLightSaving of that machine back to "correct" value (I mean, the same value with other machines).


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by MarisBo Thursday, August 25, 2011 3:17 PM
    Thursday, August 25, 2011 3:23 AM

All replies

  • I tested your project on a Windows 7 64bit machine, however, it woks well, I'm using UTC+8 time zone;

     

    As you have observed, the exception just occurs on one computer, it seems to be an environment issue, something related to the time zone and daylight saving time.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 24, 2011 3:30 AM
  • Eric Yang,

     

    Thanks for your answer. Do you have any clue, what exactly can be causing this (repair .NET, clear GAC, anything)?

    The scenario is the following: I have a computer with that faulty date thing. User who uses this computer is happy because everything else just works (Windows, Office, many other programs). She apparently does not have any other .NET app, that uses DateTime class and is compiled under x64 flag. So if my app does not work, that means that it is my fault :(

     

    So I am still waiting for an answer.

     

    Wednesday, August 24, 2011 6:25 AM
  • Could you please check the Windows Event Log?

    If the TimeZone or DayLightSaving on that machine is different agianst other machines, you can change the TimeZone and DayLightSaving of that machine back to "correct" value (I mean, the same value with other machines).


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by MarisBo Thursday, August 25, 2011 3:17 PM
    Thursday, August 25, 2011 3:23 AM
  • Eric Yang,

    Somehow I forgot to look in Windows Event Log.

    I tried to look for Event Log under Computer Management, but it was not here. Tried "Event Log" in Start Menu. It opened with error: MMC could not create the snap-in......

    So at the end I tried everything for a couple of hours. Tried to compare .NET files (64 bit DLLs) with files from another computer. Searched through the internet. Nothing.

     

    The solution was: System Restore - Found a good restore candidate - Restore - Tried to install updates one by one. Now everything works and problem is gone. So I do not know, may be some bit flipped in the RAM... who knows...

     

    Thanks for your help,

    Maris

    Thursday, August 25, 2011 3:16 PM