-4

In the event log i am getting following line, could someone please help me for this.

Event Type: Error
Event Source:   .NET Runtime
Event Category: None
Event ID:   1026
Date:       01/06/2013
Time:       11:20:06
User:       N/A
Computer:   BISO
Description:
Application: TMS.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Security.SecurityException

Stack:    at System.ThrowHelper.ThrowSecurityException(System.ExceptionResource)
at Microsoft.Win32.RegistryKey.InternalOpenSubKey(System.String, Microsoft.Win32.RegistryKeyPermissionCheck, Int32)
at Microsoft.Win32.RegistryKey.OpenSubKey(System.String, Microsoft.Win32.RegistryKeyPermissionCheck, System.Security.AccessControl.RegistryRights)
at System.TimeZoneInfo.CheckDaylightSavingTimeDisabledDownlevel()
at System.TimeZoneInfo.TryCompareTimeZoneInformationToRegistry(TimeZoneInformation, System.String, Boolean ByRef)
at System.TimeZoneInfo.FindIdFromTimeZoneInformation(TimeZoneInformation, Boolean ByRef)
at System.TimeZoneInfo.GetLocalTimeZone()    
at System.TimeZoneInfo.get_Local()
at System.DateTime.ToLocalTime()
at System.DateTime.FromFileTime(Int64)
at System.Timers.ElapsedEventArgs..ctor(Int32, Int32)
at System.Timers.Timer.MyTimerCallback(System.Object)
at System.Threading._TimerCallback.TimerCallback_Context(System.Object)
at System.Threading.ExecutionContext.runTryCode(System.Object)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading._TimerCallback.PerformTimerCallback(System.Object)

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Eoin Campbell
  • 43,500
  • 17
  • 101
  • 157
Sam Khan
  • 7
  • 4

1 Answers1

1

You have 2 problems I can see.

  1. When you run it on your own machine, the account which the application is running as has permission to access the registry, however you are missing this permission on the other machine. When you run it on the other machine, can you try run it as Administrator or with escalated privileges ?

  2. You don't have adequate exception handling in your codes Timer_Elapsed method to try/catch and handle the exception so it's crashing the entire application.

Also check if there's any anti-virus /security software running on the other machine which might be sandboxing the app or blocking access to the registry

Eoin Campbell
  • 43,500
  • 17
  • 101
  • 157
  • Another possibility is this answer here: http://stackoverflow.com/questions/4692644/asp-net-site-throwing-a-system-security-securityexception/4695303#4695303 – Eoin Campbell May 31 '13 at 11:35
  • T Actually in my application i am not trying any where to access registry values neither trying to change registry value any where. And the only thing i am doing in timer_elapsed event is writing command for ARM7 controller on serial port and on getting response taking the system time using DateTime.now() function. But thank you very much for you quick response and help. – Sam Khan May 31 '13 at 11:40
  • You're not, but the .NET framework is. If you read the stack trace when you call `System.DateTime.FromFileTime(Int64)`, it calls local time, which in turn has to get Localization settings from the Registry. this is where the call fails. In the question in my previous comment, another user had a problem because of the wrong permissions on a registry jey – Eoin Campbell May 31 '13 at 13:08
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation – Sam Khan Jun 05 '13 at 10:07
  • finally got the solution. Permission for the registery key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation on another computer was set to deny. By just unchecking those setting my application start working like a charm. Thanks to specially Eoin Campbell for directing me in the right direction. – Sam Khan Jun 05 '13 at 10:13