Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Occasional crash in TouchEffect because of wrong time zone #1999

Open
holecekp opened this issue Dec 21, 2023 · 0 comments
Open

[Bug] Occasional crash in TouchEffect because of wrong time zone #1999

holecekp opened this issue Dec 21, 2023 · 0 comments
Labels
bug Something isn't working. Breaky break.

Comments

@holecekp
Copy link

Description

DateTime.Now sometimes throws exceptions on Android because of wrong time zone data. This has been reported in dotnet/android#8090. The bug report has been closed because it cannot be reporoduced and the cause has not been found. The working workaround is to use NowUtc instead of Now as a fall-back. This solved the problem in my code. However, I have recently received other crash reports from AppCenter where the same bug is in CommunityToolkit's TouchEffect.

Would it be please possible to replace occurences of DateTime.Now with DateTime.UtcNow in the TouchEffect constructor (https://github.com/xamarin/XamarinCommunityToolkit/blob/main/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/Touch/TouchEffect.shared.cs)? They are used there anyway only as a workaround for a linker issue.

Stack Trace

Xamarin Exception Stack:
System.TimeZoneNotFoundException: Exception of type 'System.TimeZoneNotFoundException' was thrown.
  at System.TimeZoneInfo.get_Local () [0x00012] in <cb53bf87fe9b44d48a7f960c04d83290>:0
  at System.TimeZoneInfo.GetDateTimeNowUtcOffsetFromUtc (System.DateTime time, System.Boolean& isAmbiguousLocalDst) [0x00000] in <cb53bf87fe9b44d48a7f960c04d83290>:0
  at System.DateTime.get_Now () [0x00008] in <cb53bf87fe9b44d48a7f960c04d83290>:0
  at Xamarin.CommunityToolkit.Effects.TouchEffect..ctor () [0x00021] in <a221ea4c383647198845c500162d6404>:0
  at Xamarin.CommunityToolkit.Effects.TouchEffect.TryGenerateEffect (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00023] in <a221ea4c383647198845c500162d6404>:0
  at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x0012a] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00226] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.BindingExpression.Apply (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property) [0x0006b] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.Binding.Apply (System.Object context, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty, System.Boolean fromBindingContextChanged) [0x0006d] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding, System.Boolean fromStyle) [0x00091] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.BindableObject.SetBinding (Xamarin.Forms.BindableProperty targetProperty, Xamarin.Forms.BindingBase binding) [0x00000] in <fdb98549974543d69e8151b63f809e44>:0
  at MorseCode.Views.MorseCodesListPage+<InitializeComponent>_anonXamlCDataTemplate_11.LoadDataTemplate () [0x03230] in <0bdd02de54714e31b37dedfc795b4e9c>:0
  at Xamarin.Forms.ElementTemplate.CreateContent () [0x0002c] in <fdb98549974543d69e8151b63f809e44>:0
  at Xamarin.Forms.Platform.Android.TemplatedItemViewHolder.Bind (System.Object itemBindingContext, Xamarin.Forms.ItemsView itemsView, System.Action`1[T] reportMeasure, System.Nullable`1[T] size) [0x00028] in <1a87a07025014f35b0adfa51028d0901>:0
  at Xamarin.Forms.Platform.Android.ItemsViewAdapter`2[TItemsView,TItemsViewSource].BindTemplatedItemViewHolder (Xamarin.Forms.Platform.Android.TemplatedItemViewHolder templatedItemViewHolder, System.Object context) [0x00000] in <1a87a07025014f35b0adfa51028d0901>:0
  at Xamarin.Forms.Platform.Android.StructuredItemsViewAdapter`2[TItemsView,TItemsViewSource].BindTemplatedItemViewHolder (Xamarin.Forms.Platform.Android.TemplatedItemViewHolder templatedItemViewHolder, System.Object context) [0x00038] in <1a87a07025014f35b0adfa51028d0901>:0
  at Xamarin.Forms.Platform.Android.ItemsViewAdapter`2[TItemsView,TItemsViewSource].OnBindViewHolder (AndroidX.RecyclerView.Widget.RecyclerView+ViewHolder holder, System.Int32 position) [0x0004c] in <1a87a07025014f35b0adfa51028d0901>:0
  at Xamarin.Forms.Platform.Android.StructuredItemsViewAdapter`2[TItemsView,TItemsViewSource].OnBindViewHolder (AndroidX.RecyclerView.Widget.RecyclerView+ViewHolder holder, System.Int32 position) [0x00056] in <1a87a07025014f35b0adfa51028d0901>:0
  at Xamarin.Forms.Platform.Android.SelectableItemsViewAdapter`2[TItemsView,TItemsSource].OnBindViewHolder (AndroidX.RecyclerView.Widget.RecyclerView+ViewHolder holder, System.Int32 position) [0x00000] in <1a87a07025014f35b0adfa51028d0901>:0
  at Xamarin.Forms.Platform.Android.GroupableItemsViewAdapter`2[TItemsView,TItemsViewSource].OnBindViewHolder (AndroidX.RecyclerView.Widget.RecyclerView+ViewHolder holder, System.Int32 position) [0x0004b] in <1a87a07025014f35b0adfa51028d0901>:0
  at AndroidX.RecyclerView.Widget.RecyclerView+Adapter.n_OnBindViewHolder_Landroidx_recyclerview_widget_RecyclerView_ViewHolder_I (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_holder, System.Int32 position) [0x0000f] in <9f62edf4a26b41938f79cddc40df3c5c>:0
  at (wrapper delegate-invoke) <Module>.invoke_void_intptr_intptr_intptr_int(intptr,intptr,intptr,int)
  at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLI_V (_JniMarshal_PPLI_V callback, System.IntPtr jnienv, System.IntPtr klazz, System.IntPtr p0, System.Int32 p1) [0x00005] in <96af022141734842977c0f57b7524f48>:0

Link to Reproduction Sample

Cannot be reproduced (see below).

Steps to Reproduce

Unable to reproduce. The problem is only in certain time zones and probably only on certain devices there.

Expected Behavior

Random crashes on specific devices in certain time zones on Android.

Actual Behavior

No crashes

Basic Information

  • Version with issue: latest (2.0.6)
  • Last known good version: -
  • IDE: VS 17.8.3
  • Platform Target Frameworks:
    • Android: 13
  • Nuget Packages: AppCenter, Xamarin.Forms, Essentials, sqlite-net-pcl
  • Affected Devices: Galaxy J4 Core (from the latest crash report, other devices have the same problem too).

Workaround

The only workaround would be to copy all the TouchEffect's code into your solution and replace all calls of DateTime.Now with UtcNow there. More user friendly would be to fix it in the CommunityToolkit iteslf.

@holecekp holecekp added the bug Something isn't working. Breaky break. label Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working. Breaky break.
Projects
None yet
Development

No branches or pull requests

1 participant