Skip to content

Crash when CustomControl Property use StaticResource #27002

@albilaga

Description

@albilaga

Description

I have some CustomControl like this

public class CustomButton : ContentView
{
	//other code
	private ButtonConfiguration? _containedButtonConfiguration;
	public ButtonConfiguration? ButtonConfig
	{
		get => _containedButtonConfiguration;
		set
		{
			_containedButtonConfiguration = value;
			Draw();
		}
	}

	public CustomButton()
	{
		HorizontalOptions = VerticalOptions = LayoutOptions.Start;
	}
}

and ButtonConfiguration is something like this

[AcceptEmptyServiceProvider]
public abstract class ButtonConfiguration : IMarkupExtension<ButtonConfiguration>
{
	public abstract ButtonConfiguration BasedOn { set; }

	public abstract View ComposeView();
	public ButtonConfiguration ProvideValue(IServiceProvider serviceProvider)
	{
		return this;
	}

	object IMarkupExtension.ProvideValue(IServiceProvider serviceProvider)
	{
		return ProvideValue(serviceProvider);
	}

	public abstract void ApplyGestureHandler(View parentView, GestureRecognizer customGestureRecognizer);
}

and some ButtonConfiguration is like this

public class IconButtonConfiguration : ButtonConfiguration
{
	public Color? Color { get; set; }
	public string? IconGlyph { get; set; } = string.Empty;
	public double IconSize { get; set; } = 14;
}

and when I set style in App.xaml

<ResourceDictionary>
            <system:Double x:Key="LargeIconButtonFontSize">24</system:Double>
            <config:IconButtonConfiguration
                x:Key="DefaultIconButtonConfig"
                IconSize="{StaticResource LargeIconButtonFontSize}"
                SpacingEnabled="True"
                Color="Black" />
        </ResourceDictionary>

this will cause crash when in Release (both on Android and iOS). Debug working fine. But if I set like this

<ResourceDictionary>
            <system:Double x:Key="LargeIconButtonFontSize">24</system:Double>
            <config:IconButtonConfiguration
                x:Key="DefaultIconButtonConfig"
                IconSize="18"
                SpacingEnabled="True"
                Color="Black" />
        </ResourceDictionary>

it is working fine in Release. Not really sure what is the cause of this

Steps to Reproduce

  1. Clone https://github.com/albilaga/mauitest
  2. Run android or iOS project in Release. This will crash

Link to public reproduction project repository

https://github.com/albilaga/mauitest

Version with bug

9.0.21 SR2.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.100 SR10

Affected platforms

iOS, Android

Affected platform versions

iOS and Android

Did you find any workaround?

Hard code the value instead of using StaticResource but this mean then when refactoring need to be careful

Relevant log output

iOS
Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    platform/androidplatform/iospotential-regressionThis issue described a possible regression on a currently supported version., verification pending

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions