Skip to content

[Android, Windows] MauiXamlInflation - Using static binding extension to bind a static list to Picker.ItemsSource throws System.NullReferenceException #32758

@themanciraptor

Description

@themanciraptor

Description

I am testing out the new MauiXamlInflation SourceGen feature and noticed my existing projects were failing wherever I used a picker bound to a static list.

Steps to Reproduce

  1. Create new Maui project.
  2. Create a static list of items. e.g:
public static IReadOnlyList<string> PrimitiveValues => ["first","second","third"];
  1. Add a Picker Control to your mainpage template. Use the static markup extension to bind your list to the ItemsSource property of the picker. e.g.
<Picker ItemsSource="{Static local:MainPageViewModel.PrimitiveValues }">
  1. Add <MauiXamlInflator>SourceGen</MauiXamlInflator> to .csproj file.
  2. Run project. Project should fail to start after an exception is thrown: System.NullReferenceException: 'Object reference not set to an instance of an object.'

Link to public reproduction project repository

https://github.com/themanciraptor/MauiIssueRepro

Version with bug

10.0.10

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

Define the list inline. e.g:

    <Picker SelectedItem="{Binding Selected}">
      <Picker.ItemsSource>
        <Array Type="{Type local:MyEnum}">
          <local:MyEnum>None</local:MyEnum>
          <local:MyEnum>Blue</local:MyEnum>
          <local:MyEnum>Green</local:MyEnum>
          <local:MyEnum>Red</local:MyEnum>
        </Array>
      </Picker.ItemsSource>
    </Picker>

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-xamlXAML, CSS, Triggers, Behaviorsplatform/androidplatform/windowss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't workingxsgXaml sourceGen

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions