CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Bug: CollectionViewSource crash in PublishAoT mode when using IEnumerable

Open dotMorten opened this issue 1 year ago • 2 comments

Description

Binding this with PublishAoT causes a runtime crash:

    {
        get
        {
            var groups = (from item in Samples
                         orderby item.Category
                         group item by item.Category into g
                         select new SampleGroup(g) { Key = g.Key ?? "Misc" });
            return groups; // If you add .ToList() here no crash
        }
    }
    CollectionViewSource m_CollectionViewSource;
    public CollectionViewSource CollectionViewSource
    {
        get
        {
            if(m_CollectionViewSource == null)
            {
                m_CollectionViewSource = new CollectionViewSource()
                {
                    IsSourceGrouped = true,
                    Source = SamplesByCategory,
                    ItemsPath = new PropertyPath("Items")
                };
            }
            return m_CollectionViewSource;
        }
    }
}

Steps To Reproduce

  1. Run the attached project: App17.zip
  2. Observe the crash: Image
  3. Remove PublishAoT=true and sample runs
  4. Add ToList() to the SamplesByCategory return value, and problem goes away

Expected Behavior

No crash ;-)

Version Info

<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241106002" />

Additional Context

No response

dotMorten avatar Nov 13 '24 23:11 dotMorten