Skip to content

[.NET 10] Xaml Source Gen - A static anonymous function cannot contain a reference to 'extension' #32679

Closed

Description

@IeuanWalker

Description

Turned on source gen, and getting a lot of these error -
Image

This is the SG function is complaining about -

		static global::Microsoft.Maui.Controls.BindingBase CreateTypedBindingFrom_bindingExtension3(global::Microsoft.Maui.Controls.Xaml.BindingExtension extension)
{
	return Create(
		getter: static source => source.Collection.PremiseSR?.Escalate ?? extension.TargetNullValue as bool? ?? default,
		extension.Mode,
		extension.Converter,
		extension.ConverterParameter,
		extension.StringFormat,
		extension.Source,
		extension.FallbackValue,
		extension.TargetNullValue);

	[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Maui.Controls.BindingSourceGen, Version=10.0.0.0, Culture=neutral, PublicKeyToken=null", "10.0.0.0")]
	static global::Microsoft.Maui.Controls.BindingBase Create(
		global::System.Func<global::App.Routes.WasteManagement.MissedCollection.ViewModels.ReportViewModel, bool> getter,
		global::Microsoft.Maui.Controls.BindingMode mode = global::Microsoft.Maui.Controls.BindingMode.Default,
		global::Microsoft.Maui.Controls.IValueConverter? converter = null,
		object? converterParameter = null,
		string? stringFormat = null,
		object? source = null,
		object? fallbackValue = null,
		object? targetNullValue = null)
	{
		global::System.Action<global::App.Routes.WasteManagement.MissedCollection.ViewModels.ReportViewModel, bool>? setter = null;
		if (ShouldUseSetter(mode))
		{
				setter = static (source, value) =>
				{
					if (source.Collection.PremiseSR is {} p0)
					{
						p0.Escalate = value;
					}
				};
		}
		
		var binding = new global::Microsoft.Maui.Controls.Internals.TypedBinding<global::App.Routes.WasteManagement.MissedCollection.ViewModels.ReportViewModel, bool>(
			getter: source => (getter(source), true),
			setter,
			handlers: new global::System.Tuple<global::System.Func<global::App.Routes.WasteManagement.MissedCollection.ViewModels.ReportViewModel, object?>, string>[]
			{
				new(static source => source, "Collection"),
				new(static source => source.Collection, "PremiseSR"),
				new(static source => source.Collection.PremiseSR, "Escalate"),
			})
		{
			Mode = mode,
			Converter = converter,
			ConverterParameter = converterParameter,
			StringFormat = stringFormat,
			Source = source,
			FallbackValue = fallbackValue,
			TargetNullValue = targetNullValue
		};
		
		return binding;
	}


	[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
	static bool ShouldUseSetter(global::Microsoft.Maui.Controls.BindingMode mode)
		=> mode == global::Microsoft.Maui.Controls.BindingMode.OneWayToSource
			|| mode == global::Microsoft.Maui.Controls.BindingMode.TwoWay
			|| mode == global::Microsoft.Maui.Controls.BindingMode.Default;
}
		

This is the XAML its complaining about -

<?xml version="1.0" encoding="utf-8" ?>
<basePage:BasePage x:Class="App.Routes.WasteManagement.MissedCollection.Pages.SummaryPage"
                   xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                   xmlns:basePage="clr-namespace:App.BaseLayouts"
                   xmlns:buttons="clr-namespace:App.Controls.Buttons"
                   xmlns:resx="clr-namespace:App.Resources.Languages"
                   xmlns:sections="clr-namespace:App.Controls.Sections"
                   xmlns:styles="clr-namespace:App.Resources.Styles"
                   xmlns:viewmodel="clr-namespace:App.Routes.WasteManagement.MissedCollection.ViewModels"
                   Title="{x:Static resx:AppResources.PageTitleSummary}"
                   x:DataType="viewmodel:ReportViewModel">
    <basePage:BasePage.BasePageContent>
        <Grid RowDefinitions="auto,auto,auto,auto,auto,auto,auto,auto,*">
            <sections:HeaderIcon Grid.Row="0"
                                 HeadIcon="{x:Static styles:IconFont.Summary}"
                                 HeadLabel="{x:Static resx:AppResources.PageTitleReportDetails}" />
            <!-- Contact details -->
            <Label Grid.Row="1"
                   Margin="{StaticResource FormMarginsSummaryTitle}"
                   Style="{DynamicResource TextSection}"
                   Text="{x:Static resx:AppResources.TitleContactDetails}" />
            <Label Grid.Row="2"
                   Margin="{StaticResource FormMargins}"
                   Style="{DynamicResource TextBody}">
                <Label.FormattedText>
                    <FormattedString>
                        <Span Text="{x:Static resx:AppResources.LblEmail}" />
                        <Span Text=" " />
                        <Span Text="{Binding Report.EmailAddress}" />
                    </FormattedString>
                </Label.FormattedText>
            </Label>
            <!-- Address -->
            <Label Grid.Row="3"
                   Margin="{StaticResource FormMarginsSummaryTitle}"
                   Style="{DynamicResource TextSection}"
                   Text="{x:Static resx:AppResources.TitleAddress}" />
            <Label Grid.Row="4"
                   Margin="{StaticResource FormMargins}"
                   Style="{DynamicResource TextBody}"
                   Text="{Binding Address.Address}" />
            <!-- Collection type -->
            <Label Grid.Row="5"
                   Margin="{StaticResource FormMarginsSummaryTitle}"
                   Style="{DynamicResource TextSection}"
                   Text="{x:Static resx:AppResources.TitleMissedCollection}" />
            <Label Grid.Row="6"
                   Margin="{StaticResource FormMargins}"
                   Style="{DynamicResource TextBody}"
                   Text="{Binding Collection.FeatureDetails.Description}" />

            <!-- If Escalated -->
            <Border Grid.Row="7"
                    Margin="20,10,20,10"
                    IsVisible="{Binding Collection.PremiseSR.Escalate}"
                    Style="{StaticResource NoteStyle}">
                <Label Margin="0,3,0,3"
                       Style="{DynamicResource TextBody}"
                       Text="{x:Static resx:AppResources.LblMissedCollectionsEscalate}" />
            </Border>

            <buttons:NextBack Grid.Row="8"
                              ClickedCommand="{Binding SubmitCommand}"
                              IsSubmit="True"
                              VerticalOptions="End" />
        </Grid>
    </basePage:BasePage.BasePageContent>
</basePage:BasePage>

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

10.0.10

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android, iOS, I was not able test on other platforms

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

Activity

  1. added
    t/bug
    on Nov 17, 2025
  2. simonrozsival commented on Nov 18, 2025

    @simonrozsival
    Member

    @IeuanWalker thanks for reporting the bug! We have already fixed it in #32420, so I'm closing the issue now. There is a related PR #32580 which improves testing of the source generated code.

  3. locked and limited conversation to collaborators on Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    t/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions