Skip to content

Bug: Trying to enumerate the result of DisplayArea.FindAll() throws an InvalidCastException #2373

@benstevens48

Description

@benstevens48

Description

With AOT on, call Microsoft.UI.Windowing.DisplayArea.FindAll().ToList() or anything else that tries to call GetEnumerator on the result of DisplayArea.FindAll() and it fails with an InvalidCastException. The stack trace is

[System.InvalidCastException user-unhandled]	
>	WinRT.Runtime.dll!WinRT.IObjectReference.As<WinRT.Interop.IUnknownVftbl>(System.Guid iid) Line 139	C#
 	WinRT.Runtime.dll!System.Collections.Generic.IReadOnlyListImpl<Microsoft.UI.Windowing.DisplayArea>.Make_IEnumerableObjRef() Line 47	C#
 	WinRT.Runtime.dll!System.Collections.Generic.IReadOnlyListImpl<Microsoft.UI.Windowing.DisplayArea>.iEnumerableObjRef.get() Line 25	C#
 	WinRT.Runtime.dll!System.Collections.Generic.IReadOnlyListImpl<Microsoft.UI.Windowing.DisplayArea>.GetEnumerator() Line 75	C#

Note that I wouldn't say this was a duplicate of #747 as previously suggested in this issue microsoft/microsoft-ui-xaml#6454 since no covariance is involved here. Also, this is not the System.ArgumentOutOfRangeException mentioned in that issue. The workaround of using an integer indexer as in microsoft/microsoft-ui-xaml#6454 (comment) works.

Steps To Reproduce

See description

Expected Behavior

No exception

Version Info

CsWinRT 2.2, WindowsAppSdk.WinUI 1.8.260204000 (+ transitive dependencies), Windows 25H2.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions