Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical crash in WinUI with attached properties in style. #6388

Open
1 of 2 tasks
valvasiliev opened this issue Nov 26, 2021 · 6 comments
Open
1 of 2 tasks

Critical crash in WinUI with attached properties in style. #6388

valvasiliev opened this issue Nov 26, 2021 · 6 comments
Labels
area-Commanding AppBar, UICommand, MVVM, etc bug Something isn't working Crash whenever user reports a crash or app freeze product-winui3 WinUI 3 issues team-Controls Issue for the Controls team

Comments

@valvasiliev
Copy link

valvasiliev commented Nov 26, 2021

Describe the bug

You will have unexpected crash in WinUI 3 If you have a style with attached property.

Steps to reproduce the bug

  1. Create a template (buttons in my case) using a few attached properties.
  2. Use the template in the second assembly (in the button where we call this crash).
  3. Create a style in the second assembly, where we assign any attached property (if we assign all attached properties, the bug is not reproduced.). It is enough to create the style. You do not have to use it.

If we click the button - we have crash.

Same in my native language ->

  1. Создаем шаблон (кнопки в моем случае) с использованием нескольких присоединенных свойств.
  2. Используем шаблон во второй сборке (в кнопке по которой упадем).
  3. Создаем стиль во второй сборке, где присваиваем любое присоединенное свойство (если присвоить все присоединенные свойства - баг не воспроизводится.). Сам стиль можно не использовать. Достаточно его создать.

По нажатию на кнопку - падаем.

Expected behavior

No crash.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.0 (If you're seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

May 2021 Update (19043)

Additional context

See attached project

TestForMS.zip

@gabbybilka Looks like you have critical crash in WinUI. I added a simple project. Could somebody take a look?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 26, 2021
@valvasiliev valvasiliev changed the title Crash with attached properties in style. Critical crash in WinUI with attached properties in style. Dec 2, 2021
@gabbybilka
Copy link
Member

FYI @MikeHillberg

@jeromelaban
Copy link

I have the same issue, here's another repro: App176.zip.

Here's a extract:

<!-- This crashes the app-->
<ContentControl Content="42">
	<ContentControl.Template>
		<ControlTemplate TargetType="ContentControl">
			<Grid>
				<Border Tag="{Binding Path=(local:TestControlExtensions.MyProperty)}" />
			</Grid>
		</ControlTemplate>
	</ContentControl.Template>
</ContentControl>

<!--
This works:
		
<ContentControl Content="42" local:TestControlExtensions.MyProperty="{x:Null}">
	<ContentControl.Template>
		<ControlTemplate TargetType="ContentControl">
			<Grid>
				<Border Tag="{Binding Path=(local:TestControlExtensions.MyProperty)}" />
			</Grid>
		</ControlTemplate>
	</ContentControl.Template>
</ContentControl>
-->

With this attached property:

[Microsoft.UI.Xaml.Data.Bindable]
public static class TestControlExtensions
{
	public static DependencyProperty MyPropertyProperty { get; } = DependencyProperty.RegisterAttached(
		"MyProperty",
		typeof(object),
		typeof(TestControlExtensions),
		new PropertyMetadata(default));

	public static object GetMyProperty(Control obj) => (object)obj.GetValue(MyPropertyProperty);
	public static void SetMyProperty(Control obj, object value) => obj.SetValue(MyPropertyProperty, value);
}

@valvasiliev
Copy link
Author

valvasiliev commented Dec 2, 2021

@jeromelaban I do not think what it is the same. I initialize all attached properties in styles. But take a look:

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <StackPanel.Resources>
            <Style x:Key="CrashButtonStyle" TargetType="Button" >
                <Setter Property="h:ControlHelper.AnyAttached" Value="0"/>
            </Style>
        </StackPanel.Resources>
        <Button Grid.Column="1" Grid.Row="1" Content="Test" Style="{StaticResource TrueBlueButtonStyle}" />

    </StackPanel>

I only create CrashButtonStyle and do not use it. If I'll comment it in MainWindow.xaml and uncomment it in CommonStyles.xaml - I will not have any problem. (p.s. property from CrashButtonStyle not uses in template)

Because of that, I can't use attached property in style, If I use such styles it is some assemblies. To not catch this bug - I should hold all styles in one assembly (and in one file because of other bug with resource files separation, but it is other story).

WinUI have problem with attached property initialization.

@gabbybilka gabbybilka added the product-winui3 WinUI 3 issues label Feb 8, 2022
@StephenLPeters StephenLPeters added team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Feb 17, 2022
@bpulliam bpulliam added the Crash whenever user reports a crash or app freeze label Oct 13, 2022
@zhaparoff
Copy link

Any update on this? More than a year has been passed =(

@gabbybilka
Copy link
Member

@evelynwu-msft @bpulliam ?

@agneszitte
Copy link
Contributor

Any update on this? More than a year has been passed =(

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Commanding AppBar, UICommand, MVVM, etc bug Something isn't working Crash whenever user reports a crash or app freeze product-winui3 WinUI 3 issues team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

8 participants