WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

AdaptiveGridView throws argument exception

Open ranaprathap2 opened this issue 4 years ago • 11 comments

Upon resizing the control the adaptive grid view throws argument exception.

This happens when toggling the visibility of a control using the adaptive grid view. On some cases theCalculateItemWidth method returns an invalid Item width.

[Update] var columns = CalculateColumns(containerWidth, DesiredWidth); CalculateColumns method returns an invalid value (negative value) when DesiredWidth value is 0, But still can't get enough clue why the desired width is set to 0.

StackTrace is as below System.ArgumentException: Value does not fall within the expected range. at Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, Object value) at Microsoft.Toolkit.Uwp.UI.Controls.AdaptiveGridView.RecalculateLayout(Double containerWidth) at Microsoft.Toolkit.Uwp.UI.Controls.AdaptiveGridView.OnSizeChanged(Object sender, SizeChangedEventArgs e)

ranaprathap2 avatar Feb 21 '20 10:02 ranaprathap2

Hello ranaprathap2, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will investigate the issue and help solve it ASAP. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Feb 21 '20 10:02 ghost

Thanks for submitting a new feature request! I've automatically added a vote 👍 reaction to help get things started. Other community members can vote to help us prioritize this feature in the future!

ghost avatar Feb 21 '20 10:02 ghost

@ranaprathap2 I am not able to reproduce this. Can you please provide screenshot or show the detailed process so we can see how you are receiving this error?

Kyaa-dost avatar Feb 21 '20 19:02 Kyaa-dost

@ranaprathap2 could you maybe provide a small repro project that shows there error? Or is it possible to get the Sample App to hit this scenario, that's the easiest way for us to test issues and fixes?

michael-hawker avatar Apr 03 '20 21:04 michael-hawker

@ranaprathap2 Please let us know when you have an update on this.

Kyaa-dost avatar Apr 09 '20 16:04 Kyaa-dost

@ranaprathap2 can you clarify what Toolkit and OS versions you are on? I thought we fixed some issues in a similar sounding area in the last release?

michael-hawker avatar Apr 10 '20 21:04 michael-hawker

OS Name Microsoft Windows 10 Pro Version 10.0.18362 Build 18362

@michael-hawker

ranaprathap2 avatar Apr 11 '20 04:04 ranaprathap2

@ranaprathap2 is this issue still persistent?

Kyaa-dost avatar Dec 16 '20 21:12 Kyaa-dost

This is happening to me too, here is my AppCenter report from a 10.0.19043 OS.

System.Runtime.InteropServices McgMarshal.ThrowOnExternalCallFailed (Int32, RuntimeTypeHandle) __Interop ComCallHelpers.Call ($__ComObject __this, RuntimeTypeHandle __typeHnd, Int32 __targetIndex, Void* arg0, Void* arg1) Call at 15732480 System.__Canon> (Void* InstParam, $__ComObject __this, __Canon dp, Object value, Int32 __targetIndex) Stub_12 at 16707566 Microsoft.Toolkit.Uwp.UI.Controls AdaptiveGridView.RecalculateLayout (Double containerWidth) //Microsoft.Toolkit.Uwp.UI.Controls.Primitives/AdaptiveGridView/AdaptiveGridView.cs at 264:17 Microsoft.Toolkit.Uwp.UI.Controls AdaptiveGridView.OnSizeChanged (Object sender, $SizeChangedEventArgs e) //Microsoft.Toolkit.Uwp.UI.Controls.Primitives/AdaptiveGridView/AdaptiveGridView.cs at 176:17 System.Xml.Serialization XmlNodeEventHandler.Invoke (Object sender, $XmlNodeEventArgs e) Invoke at 16707566 System.__Canon> (Void* InstParam, Object __this, IntPtr pfn, __Canon arg0, __Canon arg1) __Interop.ReverseComStubs Stub_6<System.__Canon> (Void* InstParam, Object __this, Void* unsafe_sender, Void* unsafe_e, IntPtr __methodPtr) Stub_6 at 16707566 System.Runtime.InteropServices McgMarshal.ThrowOnExternalCallFailed (Int32, RuntimeTypeHandle) __Interop ComCallHelpers.Call ($__ComObject __this, RuntimeTypeHandle __typeHnd, Int32 __targetIndex) Call at 15732480 __Interop.ForwardComStubs Stub_19<System.__Canon> (Void* InstParam, $__ComObject __this, Int32 __targetIndex) Stub_19 at 16707566 Microsoft.AppCenter.Utils ApplicationLifecycleHelper.b__17_1 (Object sender, $UnhandledErrorDetectedEventArgs eventArgs)

teohumeau avatar Nov 28 '21 09:11 teohumeau

Is there any fix available ?

From the v7.1.2 on a 10.0.22000 OS, AppCenter report this:

Date/Time: 2022-03-03T15:26:42.3980346Z OS Version: 10.0.22000 (10.0.22000.493)

Exception Type: System.ArgumentException

Application Specific Information: *** Terminating app due to uncaught exception 'System.ArgumentException', reason: 'Value does not fall within the expected range.'

Last Exception Backtrace: 0 System.Runtime.InteropServices 0x7fffdc24ef71 System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21 1 __Interop 0x7fff7d55d652 __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Void*, Void*) + 0xc2 2 ??? 0x7fff7d55f8f4 __Interop.ForwardComStubs.Stub_12[TThis, TArg0](__ComObject, TArg0, Object, Int32) + 0x74 3 Microsoft.Toolkit.Uwp.UI.Controls 0x7fff7daeb40a Microsoft.Toolkit.Uwp.UI.Controls.AdaptiveGridView.RecalculateLayout(Double) + 0x1ba 4 Microsoft.Toolkit.Uwp.UI.Controls 0x7fff7e85cf3e Microsoft.Toolkit.Uwp.UI.Controls.AdaptiveGridView.OnSizeChanged(Object, SizeChangedEventArgs) + 0x23e 5 System.Xml.XmlTextReaderImpl 0x7fff7d5e804e System.Xml.XmlTextReaderImpl.OnDefaultAttributeUseDelegate.Invoke(IDtdDefaultAttributeInfo, XmlTextReaderImpl) + 0x2e 6 __Interop 0x7fff7dc2a3c6 __Interop.Intrinsics.HasThisCall__24[TArg0](Object, IntPtr, Object, TArg0) + 0x36 7 ??? 0x7fff7dc2a320 AppName!<BaseAddress>+0x283a320 8 System.Runtime.InteropServices 0x7fffdc24ef71 System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21 9 __Interop 0x7fff7d558a08 __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32) + 0xb8 10 __Interop 0x7fff7d558944 __Interop.ForwardComStubs.Stub_21[TThis](__ComObject, Int32) + 0x24 11 Microsoft.AppCenter.Utils 0x7fff7db8469d Microsoft.AppCenter.Utils.ApplicationLifecycleHelper.<.ctor>b__17_1(Object, UnhandledErrorDetectedEventArgs) + 0x3d

Hope this will help.

teohumeau avatar Mar 04 '22 08:03 teohumeau

Below is some additional information and reproduction case for a crash that may have the same origin as this issue.

Describe the bug

AdaptiveGridView crashes application when sizing page width to zero when setting DesiredWidth.

If using the DesiredWidth property of the CommunityToolkit.WinUI.UI.Controls.AdaptiveGridView it crashes the whole application when the user tries to size the width of a window (or sub-control) down to zero.

System.Exception {System.ArgumentException}
Microsoft.UI.Xaml.UnhandledExceptionEventArgs}
	Exception	{"Value does not fall within the expected range."}	

Steps to reproduce

The following XAML code causes the crash when the user resizes the window width below 200, i.e. just about when the second grid column reaches the size of 0:

<Window
    x:Class="AdaptiveGridViewCrashTest.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
    mc:Ignorable="d">

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="200"/>
      <ColumnDefinition Width="*"/>
    </Grid.ColumnDefinitions>

    <Border Grid.Column="0" Background="DarkMagenta"/>

    <controls:AdaptiveGridView Grid.Column="1"
                               DesiredWidth="200">
      <controls:AdaptiveGridView.Items>
        <TextBlock Text="Sample text"/>
      </controls:AdaptiveGridView.Items>
    </controls:AdaptiveGridView>

  </Grid>

</Window>

Stack trace

>	AdaptiveGridViewCrashTest.dll!AdaptiveGridViewCrashTest.App.InitializeComponent.AnonymousMethod__4_1(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) Line 68	C#
 	Microsoft.WinUI.dll!WinRT._EventSource_global__Microsoft_UI_Xaml_UnhandledExceptionEventHandler.EventState.GetEventInvoke.AnonymousMethod__1_0(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)	Unknown
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.UnhandledExceptionEventHandler.Do_Abi_Invoke(System.IntPtr thisPtr, System.IntPtr sender, System.IntPtr e)	Unknown
 	[Native to Managed Transition]	
 	Microsoft.ui.xaml.dll!DirectUI::CFTMEventSource<struct ABI::Microsoft::UI::Xaml::IUnhandledExceptionEventHandler,struct ABI::Microsoft::UI::Xaml::IApplication,struct ABI::Microsoft::UI::Xaml::IUnhandledExceptionEventArgs>::Raise(struct ABI::Microsoft::UI::Xaml::IApplication *,struct ABI::Microsoft::UI::Xaml::IUnhandledExceptionEventArgs *)	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FrameworkApplication::RaiseUnhandledExceptionEvent(long,struct HSTRING__ *,bool *)	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::ErrorHelper::RaiseUnhandledExceptionEvent(long,class xstring_ptr const &,bool *)	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::ErrorHelper::ProcessUnhandledError(class DirectUI::ErrorInfo &,bool,bool *)	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::FinalUnhandledErrorDetectedRegistration::OnFinalUnhandledErrorDetected(struct IInspectable *,struct ABI::Windows::ApplicationModel::Core::IUnhandledErrorDetectedEventArgs *)	Unknown
 	Microsoft.ui.xaml.dll!Microsoft::WRL::Details::DelegateArgTraits<long >::DelegateInvokeHelper<struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<2>,struct ABI::Windows::Foundation::IEventHandler<class ABI::Windows::ApplicationModel::Core::UnhandledErrorDetectedEventArgs *>,class Microsoft::WRL::FtmBase>,class `Microsoft::WRL::Callback<struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<2>,struct ABI::Windows::Foundation::IEventHandler<class ABI::Windows::ApplicationModel::Core::UnhandledErrorDetectedEventArgs *>,class Microsoft::WRL::FtmBase>,long >(long )'::`2'::<lambda_1>,1,struct IInspectable *,struct ABI::Windows::ApplicationModel::Core::IUnhandledErrorDetectedEventArgs *>::Invoke(struct IInspectable *,struct ABI::Windows::ApplicationModel::Core::IUnhandledErrorDetectedEventArgs *)	Unknown
 	twinapi.appcore.dll!Windows::Internal::Details::GitInvokeHelper<struct Windows::Foundation::IEventHandler<class Windows::ApplicationModel::Core::UnhandledErrorDetectedEventArgs *>,class Windows::Internal::GitPtr,2>::Invoke(struct IInspectable *,struct Windows::ApplicationModel::Core::IUnhandledErrorDetectedEventArgs *)	Unknown
 	twinapi.appcore.dll!Windows::ApplicationModel::Core::UnhandledErrorInvokeHelper::Invoke(struct IInspectable *,struct Windows::ApplicationModel::Core::IUnhandledErrorDetectedEventArgs *)	Unknown
 	twinapi.appcore.dll!Microsoft::WRL::InvokeTraits<2>::InvokeDelegates<class <lambda_f665aa94b11ee3164e641e3706519d88>,struct Windows::Foundation::IEventHandler<class Windows::ApplicationModel::Core::UnhandledErrorDetectedEventArgs *> >(class <lambda_f665aa94b11ee3164e641e3706519d88>,class Microsoft::WRL::Details::EventTargetArray *,class Microsoft::WRL::EventSource<struct Windows::Foundation::IEventHandler<class Windows::ApplicationModel::Core::UnhandledErrorDetectedEventArgs *>,struct Microsoft::WRL::InvokeModeOptions<2> > *)	Unknown
 	twinapi.appcore.dll!Microsoft::WRL::EventSource<struct Windows::Foundation::IEventHandler<class Windows::ApplicationModel::Core::UnhandledErrorDetectedEventArgs *>,struct Microsoft::WRL::InvokeModeOptions<2> >::DoInvoke<class <lambda_f665aa94b11ee3164e641e3706519d88> >(class <lambda_f665aa94b11ee3164e641e3706519d88>)	Unknown
 	twinapi.appcore.dll!Windows::ApplicationModel::Core::CoreApplication::ForwardLocalError(struct IRestrictedErrorInfo *)	Unknown
 	twinapi.appcore.dll!Windows::ApplicationModel::Core::CoreApplicationFactory::ForwardLocalError(struct IRestrictedErrorInfo *)	Unknown
 	combase.dll!CallErrorForwarder(void * hProcess, int fLocal, IRestrictedErrorInfo * pRestrictedErrorInfo) Line 1601	C++
 	combase.dll!RoReportUnhandledError(IRestrictedErrorInfo * pRestrictedErrorInfo) Line 1704	C++
 	Microsoft.ui.xaml.dll!DirectUI::ErrorHelper::ReportUnhandledError(long)	Unknown
 	Microsoft.ui.xaml.dll!DirectUI::DXamlCore::RaiseEvent()	Unknown
 	Microsoft.ui.xaml.dll!CLayoutManager::RaiseSizeChangedEvents()	Unknown
 	Microsoft.ui.xaml.dll!CLayoutManager::UpdateLayout()	Unknown
 	Microsoft.ui.xaml.dll!CCoreServices::NWDrawTree()	Unknown
 	Microsoft.ui.xaml.dll!CCoreServices::NWDrawMainTree()	Unknown
 	Microsoft.ui.xaml.dll!CWindowRenderTarget::Draw()	Unknown
 	Microsoft.ui.xaml.dll!CXcpBrowserHost::OnTick()	Unknown
 	Microsoft.ui.xaml.dll!CXcpDispatcher::Tick()	Unknown
 	Microsoft.ui.xaml.dll!CXcpDispatcher::OnReentrancyProtectedWindowMessage(struct HWND__ *,unsigned int,unsigned int,long)	Unknown
 	Microsoft.ui.xaml.dll!CDeferredInvoke::DispatchQueuedMessage(bool *,bool *)	Unknown
	[...]

Workaround

The crash does not occur if a MinWidth of atleast 4 is applied to the AdaptiveGridView.

    <controls:AdaptiveGridView Grid.Column="1"
                               MinWidth="4"
                               DesiredWidth="200">

Environment

Visual Studio 2022 17.5.4 CommunityToolkit.WinUI.UI.Controls 7.1.2 Microsoft.Windows.SDK.BuildTools 10.0.22621.756 Microsoft.WindowsAppSDK 1.3.230331000

kjean667 avatar Apr 19 '23 11:04 kjean667