diff --git a/src/Uno.UI/UI/Xaml/UIElement.wasm.cs b/src/Uno.UI/UI/Xaml/UIElement.wasm.cs index 82cd2a11c3bc..c13ccb516858 100644 --- a/src/Uno.UI/UI/Xaml/UIElement.wasm.cs +++ b/src/Uno.UI/UI/Xaml/UIElement.wasm.cs @@ -326,23 +326,21 @@ partial void ApplyNativeClip(Rect rect) internal static UIElement GetElementFromHandle(IntPtr handle) { - var gcHandle = GCHandle.FromIntPtr(handle); - - if (gcHandle.IsAllocated && gcHandle.Target is UIElement element) + if (handle != IntPtr.Zero) { - return element; - } - - return null; - } - - internal static UIElement GetElementFromHandle(int handle) - { - var gcHandle = GCHandle.FromIntPtr((IntPtr)handle); + var gcHandle = GCHandle.FromIntPtr(handle); - if (gcHandle.IsAllocated && gcHandle.Target is UIElement element) + if (gcHandle.IsAllocated && gcHandle.Target is UIElement element) + { + return element; + } + } + else { - return element; + if (typeof(UIElement).Log().IsEnabled(Uno.Foundation.Logging.LogLevel.Debug)) + { + typeof(UIElement).Log().Debug($"Unable to get element handle for uninitialized handle"); + } } return null;