dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.27k stars 1.76k forks source link

Application works in Debug build but crashes in Release build when binding ImmutableArray to ItemsSource with x:Static #24384

Open andrekoehler opened 3 months ago

andrekoehler commented 3 months ago

Description

The application works in Debug build but crashes in Release build as soon as navigating to the XAML that uses x:Static to bind Picker.ItemsSource to an ImmutableArray.

Steps to Reproduce

  1. Create a new MAUI app
  2. Add SomeViewModel.cs:
    namespace MauiApp1;
    public class SomeViewModel
    {
    public System.Collections.Immutable.ImmutableArray<string> Letters => ["A", "B", "C"];
    public static System.Collections.Immutable.ImmutableArray<string> StaticLetters => ["A", "B", "C"];
    }
  3. Add this to MainPage.xaml:

        <!-- crashes only in Release build -->
        <Picker ItemsSource="{x:Static local:SomeViewModel.StaticLetters}" />
    
        <!-- works in Debug and Release build -->
        <!--<Picker ItemsSource="{Binding Letters}" />-->
  4. Select Release build and run the app on Windows Machine
  5. The app will immediately crash if the picker is on the MainPage. In my actual app it crashes as soon as I enter the page with the picker.

Link to public reproduction project repository

No response

Version with bug

8.0.61 SR6.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

net8.0-windows10.0.19041.0

Did you find any workaround?

Do not use a static property with x:Static, instead use a non-static property with Binding.

Relevant log output

Windows Event Log show the following for the crash:

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Application Error" Guid="{a0e9b465-b939-57d7-b27d-95d8e925ff57}" /> 
  <EventID>1000</EventID> 
  <Version>0</Version> 
  <Level>2</Level> 
  <Task>100</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x8000000000000000</Keywords> 
  <TimeCreated SystemTime="2024-08-22T15:10:30.0419212Z" /> 
  <EventRecordID>21892</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="36660" ThreadID="2852" /> 
  <Channel>Application</Channel> 
  <Computer>DEV</Computer> 
  <Security UserID="S-1-5-21-3321493303-1542447700-3530763417-1001" /> 
  </System>
- <EventData>
  <Data Name="AppName">MauiApp1.exe</Data> 
  <Data Name="AppVersion">1.0.0.0</Data> 
  <Data Name="AppTimeStamp">66960000</Data> 
  <Data Name="ModuleName">Microsoft.ui.xaml.dll</Data> 
  <Data Name="ModuleVersion">3.1.5.0</Data> 
  <Data Name="ModuleTimeStamp">cd7cc268</Data> 
  <Data Name="ExceptionCode">c000027b</Data> 
  <Data Name="FaultingOffset">00000000004051c5</Data> 
  <Data Name="ProcessId">0x7fc4</Data> 
  <Data Name="ProcessCreationTime">0x1daf4a56cc91dbf</Data> 
  <Data Name="AppPath">C:\dev\_test\MauiApp1\bin\Release\net8.0-windows10.0.19041.0\win10-x64\AppX\MauiApp1.exe</Data> 
  <Data Name="ModulePath">C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.5_5001.214.1843.0_x64__8wekyb3d8bbwe\Microsoft.ui.xaml.dll</Data> 
  <Data Name="IntegratorReportId">0316a482-2d1f-4afa-9ce4-490c681db1d4</Data> 
  <Data Name="PackageFullName">com.companyname.mauiapp1_1.0.0.1_x64__9zz4h110yvjzm</Data> 
  <Data Name="PackageRelativeAppId">App</Data> 
  </EventData>
  </Event>
github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

kevinxufei commented 3 months ago

I can repro this issue at Windows platform on the latest 17.12.0 Preview 1.0(8.0.80 & 8.0.61 & 8.0.40). MauiApp22.zip